我创建了一个CPT,允许用户向页面添加人员。我已经创建了一个显示所有人的页面模板。此页面还显示用于人员的所有类别。我的问题是:当用户单击某个类别时,如何实现这一点?只有拥有该类别的人才会显示出来?
以下是相关代码摘录:
function.php (注册分类法):
function create_people_taxonomies() {
$labels = array(
\'name\' => _x( \'Categories\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Category\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Categories\' ),
\'all_items\' => __( \'All Categories\' ),
\'parent_item\' => __( \'Parent Category\' ),
\'parent_item_colon\' => __( \'Parent Category:\' ),
\'edit_item\' => __( \'Edit Category\' ),
\'update_item\' => __( \'Update Category\' ),
\'add_new_item\' => __( \'Add New Category\' ),
\'new_item_name\' => __( \'New Category Name\' ),
\'menu_name\' => __( \'Categories\' ),
);
$args = array(
\'hierarchical\' => true, // Set this to \'false\' for non-hierarchical taxonomy (like tags)
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'categories\' ),
);
register_taxonomy( \'people_categories\', array( \'people\' ), $args );
}
add_action( \'init\', \'create_people_taxonomies\', 0 );
page-cpt-people.php (显示类别的页面模板):
<?php
$taxonomy = \'people_categories\';
$terms = get_terms($taxonomy); // Get all terms of a taxonomy
if ( $terms && !is_wp_error( $terms ) ) :
?>
<ul>
<?php foreach ( $terms as $term ) { ?>
<li><a href="<?php echo get_term_link($term->slug, $taxonomy); ?>"><?php echo $term->name; ?></a></li>
<?php } ?>
</ul>
<?php endif;?>
?>
My questions: 我需要给我的分类页面指定哪个文件名,以便用户在点击cpt people页面中的一个类别时可以直接访问该页面。php分类页面需要包含哪些代码,以便循环仅显示选定类别的人员