wordpress每页不同的帖子数量

时间:2012-09-15 16:10:42

标签: wordpress-theming wordpress

我的wordpress会在主页上显示最近的帖子。设置为每页18个帖子。如何制定一些规则以在第一页(已配置)上显示18个帖子,在第二页和后续页面上显示8个帖子?

<?php while ( have_posts() ) : the_post();  
    get_template_part( 'content', get_post_format() );
endwhile; ?>

尝试了以下内容:

add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ($query->is_main_query()){
    if (is_home()){
        $query->set('showposts', 18);
    }
    else {
        $query->set('showposts',7);
        $query->set('posts_per_page',7);
    }
}
return $query;
}

没效果: - (

1 个答案:

答案 0 :(得分:2)

您可以使用函数is_home()来检查您的位置: http://codex.wordpress.org/Function_Reference/is_home

在你的php函数中,如果你不在家,你可以更改每页的帖子号,但它可能会对你的导航功能产生一些问题。

你试过这个插件吗? http://wordpress.org/extend/plugins/custom-posts-per-page/

它可能包含一些有趣的代码来解决您的问题。

相关问题