为自定义帖子类型启用类别分类法,或为默认页面帖子类型启用类别分类法:
function wpa_cats_for_pages(){
register_taxonomy_for_object_type( \'category\', \'page\' );
}
add_action( \'init\', \'wpa_cats_for_pages\' );
然后在页面模板中,获取分配给客户端页面的类别ID,并创建一个新查询,该查询传递这些ID:
// get IDs of categories assigned to this client page
$categories = wp_get_object_terms( $post->ID, \'category\', array( \'fields\' => \'ids\' ) );
// query for posts with categories that match those assigned to this page
$args = array(
\'posts_per_page\' => -1, // get all matching posts
\'category__in\' => $categories
);
$client_posts = new WP_Query( $args );
// output post data
while( $client_posts->have_posts() ):
$client_posts->the_post();
the_title();
endwhile;
// reset the global $post object so template tags for this page work as expected
wp_reset_postdata();
然后,对于每个客户端页面,您只需选择要在该页面上显示的帖子类别,就像为帖子分配类别一样。