比如我的分类目录一是显示新闻的,每页显示20骗文章。我的分类目录二是相册分类页,每页显示10篇。如何控制呢?
这个问题,主要是判断你当前分类的ID,然后按照你的意愿 ,向pre_get_posts添加自定义函数就可以了。
if ( is_category() { $cid = get_queried_object_id(); if ( $cid == '新闻分类ID' ){ $posts_per_page = 20 } if ( $cid == '相册分类ID' ){ $posts_per_page = 10 } add_action('pre_get_posts', 'custom_posts_per_page'); function custom_posts_per_page( $query ) { $query->set( 'posts_per_page', $posts_per_page ); return; }}
注明:本文为星速云原创版权所有,禁止转载,一经发现将追究版权责任!