在Wordpress的自定义分类页面中每页显示帖子数

问题描述 投票:0回答:1

我在functions.php中具有以下功能,该功能更改了自定义帖子类型存档页面中每页显示的帖子数。我还如何定位相应的分类页面(taxonomy-case.php)?是否有类似于“ is_post_type_taxonomy”的内容?

// Post number limits
function my_cptui_change_posts_per_page( $query ) {
    if ( is_admin() || ! $query->is_main_query() ) {
       return;
    }

    if ( is_post_type_archive( 'case' ) ) {
       $query->set( 'posts_per_page', 8 );
    }
}
add_filter( 'pre_get_posts', 'my_cptui_change_posts_per_page' );
wordpress custom-post-type taxonomy
1个回答
0
投票

is_tax()函数应完成您想要的工作。

// Post number limits
function my_cptui_change_posts_per_page( $query ) {
    if ( is_admin() || ! $query->is_main_query() ) {
       return;
    }

    if ( is_post_type_archive( 'case' || is_tax( 'case' ) ) ) {   // Or whatever your taxonomy name is
       $query->set( 'posts_per_page', 8 );
    }
}
add_filter( 'pre_get_posts', 'my_cptui_change_posts_per_page' );
© www.soinside.com 2019 - 2024. All rights reserved.