2014-09-25 69 views
0

我試圖破解一個WordPress主題,它使用WP_Query作爲「Recent Posts」小部件。目前僅限於返回特定的類別,但我希望它返回所有類別的有限數量的帖子。我已經嘗試過,並在其他插件/主題之前成功。在這種情況下,它不起作用,無論我嘗試實施哪些更改,我在查詢中獲得4000多個帖子。WP_Query返回無限數量的帖子,showposts和posts_per_page不工作

  <?php $the_query = new WP_Query('cat='.$category.'&showposts='.$postnum); 
     while ($the_query->have_posts()) : $the_query->the_post();?> 

什麼能沒有showposts或post_per_page正常工作作爲一個限制器的共同罪魁禍首?

+0

'showposts'已取代......您可能需要使用'posts_per_page'嘗試。 – rnevius 2014-09-25 08:33:09

+0

是的,我試了兩個,對不起,如果我的措辭不清楚。與任一個結果相同。 – wpachilles 2014-09-25 11:39:11

回答

0

你能從變量$ postnum中獲得正確的輸出嗎?

也嘗試使用這個

$args = array('category_name' => 'my-category-slug', 'posts_per_page' => 3);

<?php query_posts($args); while (have_posts()) : the_post(); echo 'content'; endwhile; wp_reset_query(); ?>

+0

是的,$ postnum工作正常。只要我刪除cat = $ category部分,問題就會顯現出來,從而有效地打破了後限制。只要我在那裏有類別參數,它就可以工作。 – wpachilles 2014-09-25 13:13:27