开发者

Paging on Index Page Not Working With posts_per_page

I'm working on a theme that has both a project page and a blog. I want to keep the blog posts at the default of 10, so I used the posts_per_page option to limit the number of projects on the first page, like this:

<?php $catID = get_cat_id('Projects');
$number = get_option('grd_portfolio_number');
if(have_posts()) : 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('paged=' . $paged . '&posts_per_page=' . $number . '&cat=' . $catID); ?>
<?php while(have_posts()) : the_post();开发者_StackOverflow社区 ?>

So if I set it to 4 (from the Theme Options page, not settings), it limits the first page to 4 projects, but the second page doesn't show anything, but if I go to my WP settings and replace that 10 to a 4, it will display the rest of my content properly.

I'm guessing that the setting is overriding something, but I can't figure out how to fix it.


If you just want to change the posts per page and keep all other parameters as before (like category, pagenumber, year in archive etc.) just add only the posts_per_page to the query string:

// put this at the top of your function
global $query_string;
..
// append the posts_per_page parameter to the other parameters
query_posts($query_string.'&posts_per_page=' . $number . ');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜