我在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' );
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' );