Estrarre posts di una categoria wordpress
-
finalmente sono riuscito a strutturare l'home page di wordpress a sezioni.
ora ho incontrato un piccolo problema.....
sto cercando di richiamare i post di determinate categorie in ciascuna delle sezioni con questo codice[FONT=Courier New]<?php query_posts('cat=1&showposts=2'); ?>[/FONT] [FONT=Verdana]<?php if (have_posts()) : ?>[/FONT] [FONT=Verdana]<?php while (have_posts()) : the_post(); ?>[/FONT]funziona, ma se provo a replicare la query mi dà errore.
soluzione? -
Che errore?
-
-
stef84
questo errore:
Parse error: syntax error, unexpected $end in /web/htdocs/www.miosito.com/home/wordpress/wp-content/themes/miotema/index.php on line 176
Credo che devi chiudere i blocchi if e while
<?php query_posts('cat=1&showposts=2'); ?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> //... tuo codice... <?php endwhile; ?> <?php endif; ?> -
perfetto funziona, grazie!
ora ho un altro problema.....
se provo ad estrarre gli ultimi topic dal forum con il codice qui sotto (che utilizzo da tempo e funziona benissimo)<? $ris_query = "SELECT topic_poster, topic_id, topic_title, username FROM phpbb_topics INNER JOIN phpbb_users ON topic_poster = user_id WHERE forum_id!=10 AND forum_id!=9 AND forum_id!=8 ORDER BY topic_time DESC LIMIT 10"; $db = mysql_connect("xx.xxx.xxx.xx","Sqlxxxxx","xxxxxxxx"); $res = mysql_db_query("Sqlxxxxx_x",$ris_query) or die('errore'); $num_righe = mysql_num_rows($res); ?> <? if($num_righe > 0) { ?> <table border="0" cellpadding="0" cellspacing="0"> <? $i = 0; while($i < $num_righe) { $topic_id = mysql_result($res,$i,"topic_id"); $topic_title = mysql_result($res,$i,"topic_title"); if (strlen($topic_title)>43) $topic_title = substr($topic_title,0,40) . '...'; $username = mysql_result($res,$i,"username"); $topic_poster = mysql_result($res,$i,"topic_poster"); echo "<tr>"; echo "<td><a href=\"[URL]http://www.miosito.com/community/viewtopic.php?t=$topic_id\[/URL]" target=\"_blank\" title=\"$topic_title\" class='topic_title'>$topic_title</td>"; echo "</tr>"; echo "<tr>"; echo "<td>postato da: <a href=\"[URL]http://www.miosito.com/community/profile.php?mode=viewprofile&u=$topic_poster\[/URL]" target=\"_blank\" title=\"$username\" class='topic_poster'>$username</td>"; echo "</tr>"; echo "<tr>"; echo "<td> </td>"; echo "</tr>"; $i++; } ?> </table> <? } else echo "Nessun topic presente"; ?>in ciascuna tabella dove estraggo i posts di wordpress mi dà questo errore
[B]WordPress database error:[/B] [Table 'Sqlxxxxx_x.wp_posts' doesn't exist] SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts LEFT JOIN wp_post2cat ON (wp_posts.ID = wp_post2cat.post_id) WHERE 1=1 AND wp_post2cat.category_id IN (4) AND (post_type = 'post' AND (post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY post_date DESC LIMIT 0, 1 -
stef84
perfetto funziona, grazie!
ora ho un altro problema.....
se provo ad estrarre gli ultimi topic dal forum con il codice qui sotto (che utilizzo da tempo e funziona benissimo)<? $ris_query = "SELECT topic_poster, topic_id, topic_title, username FROM phpbb_topics INNER JOIN phpbb_users ON topic_poster = user_id WHERE forum_id!=10 AND forum_id!=9 AND forum_id!=8 ORDER BY topic_time DESC LIMIT 10"; $db = mysql_connect("xx.xxx.xxx.xx","Sqlxxxxx","xxxxxxxx"); $res = mysql_db_query("Sqlxxxxx_x",$ris_query) or die('errore'); $num_righe = mysql_num_rows($res); ?> <? if($num_righe > 0) { ?> <table border="0" cellpadding="0" cellspacing="0"> <? $i = 0; while($i < $num_righe) { $topic_id = mysql_result($res,$i,"topic_id"); $topic_title = mysql_result($res,$i,"topic_title"); if (strlen($topic_title)>43) $topic_title = substr($topic_title,0,40) . '...'; $username = mysql_result($res,$i,"username"); $topic_poster = mysql_result($res,$i,"topic_poster"); echo "<tr>"; echo "<td><a href=\"[URL="http://www.miosito.com/community/viewtopic.php?t=$topic_id%5C"]http://www.miosito.com/community/viewtopic.php?t=$topic_id\[/URL]" target=\"_blank\" title=\"$topic_title\" class='topic_title'>$topic_title</td>"; echo "</tr>"; echo "<tr>"; echo "<td>postato da: <a href=\"[URL="http://www.miosito.com/community/profile.php?mode=viewprofile&u=$topic_poster%5C"]http://www.miosito.com/community/profile.php?mode=viewprofile&u=$topic_poster\[/URL]" target=\"_blank\" title=\"$username\" class='topic_poster'>$username</td>"; echo "</tr>"; echo "<tr>"; echo "<td> </td>"; echo "</tr>"; $i++; } ?> </table> <? } else echo "Nessun topic presente"; ?>in ciascuna tabella dove estraggo i posts di wordpress mi dà questo errore
[B]WordPress database error:[/B] [Table 'Sqlxxxxx_x.wp_posts' doesn't exist] SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts LEFT JOIN wp_post2cat ON (wp_posts.ID = wp_post2cat.post_id) WHERE 1=1 AND wp_post2cat.category_id IN (4) AND (post_type = 'post' AND (post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY post_date DESC LIMIT 0, 1Credo dipenda dal fatto che ti connetti ad un altro DB
$db = mysql_connect("xx.xxx.xxx.xx","Sqlxxxxx","xxxxxxxx");Per poi ritornare ad eseguire query ma sul db di phpBB.
Prova a chiudere la connessionedel db di phpbb e riaprire quella del db di wordpress. -
Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.
Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.
Con il tuo contributo, questo post potrebbe essere ancora migliore 💗
Registrati Accedi