http://blog.DoZarte.com


Elencare i post di una categoria


Share to Facebook Share to Twitter Stumble It Email This More...

Per WordPress esiste un plugin che permette di elencare i titoli degli articoli presenti in una categoria.
Si tratta di Category Posts, che però non funziona immediatamente se installato così com’è nelle ultime versioni di WP; infatti può succedere di ritrovarsi un errore (tipo: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource) anzichè la nostra lista di articoli!

Ho trovato una dritta sul forum di supporto di WP che indica come modificare il codice: basta sostituire…

$get_posts_in_cat = "SELECT $wpdb->posts.ID, $wpdb->posts.post_title, ";
$get_posts_in_cat .= "$wpdb->post2cat.post_id, $wpdb->post2cat.category_id ";
$get_posts_in_cat .= "FROM $wpdb->posts, $wpdb->post2cat ";
$get_posts_in_cat .= "WHERE $wpdb->posts.ID = $wpdb->post2cat.post_ID ";
$get_posts_in_cat .= "AND $wpdb->post2cat.category_id = '$catID' ";
$get_posts_in_cat .= "AND $wpdb->posts.post_status = 'publish' ";
$get_posts_in_cat .= "ORDER BY $wpdb->posts.post_title ";

…con…

$tp = $wpdb->prefix;
$get_posts_in_cat = "SELECT ID, {$tp}term_taxonomy.term_id as category_id, post_title
FROM {$tp}posts, {$tp}term_relationships, {$tp}term_taxonomy
WHERE {$tp}posts.ID = {$tp}term_relationships.object_id
AND {$tp}term_relationships.term_taxonomy_id = {$tp}term_taxonomy.term_taxonomy_id
AND {$tp}term_taxonomy.taxonomy = 'category'
AND {$tp}term_taxonomy.term_id = '$catID'
AND post_status = 'publish'
AND post_type = 'post'
ORDER BY post_title ";

…e tutto pare fortunatamente risolversi.

Se qualcuno che ne capisce di PHP/MySQL più di me fosse così gentile da spiegare il perchè, è gradito un commento!


Share to Facebook Share to Twitter Stumble It Email This More...

Se l'articolo era interessante, forse troverai approfondimenti nei seguenti link sponsorizzati...


Leave a Reply

XHTML: Tags concessi: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

You can add images to your comment by clicking here.