您可以使用Advanced Custom Fields 添加两个管理员可以选择类别的字段。然后在索引页上,使用get_field 要显示的类别。
该字段可以返回WP taxonomy对象,也可以仅返回类别ID(我已经使用过)。在您的索引中,您可以获得帖子:
$category_id_1 = get_field(\'category_1\'));
$category_id_2 = get_field(\'category_2\'));
$container_1_posts = get_posts(array(
\'posts_per_page\' => 5,
\'cat\' => $category_id_1,
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
));
$container_2_posts = get_posts(array(
\'posts_per_page\' => 5,
\'cat\' => $category_id_2,
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
));