下面是正确的实现:
注册category
的分类法page
岗位类型:
function wpse121285_add_category_to_pages() {
register_taxonomy_for_object_type(\'category\', \'page\');
}
add_action( \'admin_init\', \'wpse121285_add_category_to_pages\' );
将适当的类别术语添加到所需页面。
然后修改默认值$wp_query
对象位于pre_get_posts
:
function wpse121285_pre_get_posts( $query ) {
// Main query for the blog posts index
// Note that you can use most/any contextual
// conditional here, depending on your needs
if ( is_home() && $query->is_main_query() ) {
$query->set( \'posts_per_page\', 5 );
$query->set( \'category_name\', \'news\' );
$query->set( \'post_type\', array( \'post\', \'page\' ) );
}
}
add_action( \'pre_get_posts\', \'wpse121285_pre_get_posts\' );
保留默认循环标记:
// No query_posts() needed here!
if ( have_posts() ) : while ( have_posts() ) : the_post();