如何将指定类别的帖子的限制数量设置到该类别的页面中? [英] How can I set the limit number of the posts of a specify category into a page of that category?

查看:67
本文介绍了如何将指定类别的帖子的限制数量设置到该类别的页面中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何设置在指定类别的页面中可见的帖子的数量限制.

I would to know how can I set the limit number of the posts visible into a page of a specify category.

推荐答案

将其放在您的functions.php中

Put this in your functions.php

function main_query_mods( $query ) {
    if(!$query->is_main_query()) {
        return;
    }
    // show 15 posts per page if category has id 7
    // check http://codex.wordpress.org/Conditional_Tags#A_Category_Page
    if ( is_category('7')) {
        $query->set('posts_per_page',15);
    }
}
add_action( 'pre_get_posts', 'main_query_mods' );

这篇关于如何将指定类别的帖子的限制数量设置到该类别的页面中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆