如何创建仅显示来自自定义帖子类型的帖子的 category.php 模板(例如 category-testimonial.php)?
这是我创建自定义帖子类型的代码:
function testimonials_custom_init() {
$labels = array(
'name' => _x('Testimonials', 'post type general name'),
'singular_name' => _x('Testimonial', 'post type singular name'),
'add_new' => _x('Add New', 'testimonial'),
'add_new_item' => __('Add New Testimonial'),
'edit_item' => __('Edit Item'),
'new_item' => __('New Testimonial'),
'view_item' => __('View Testimonial'),
'search_items' => __('Search Testimonials'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'query_var' => true,
'rewrite' => array('slug','pages'),
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 5,
'has_archive' => 'testimonials',
'supports' => array('title','editor','thumbnail','excerpt',)
);
register_post_type( 'testimonials' , $args );
}
add_action( 'init', 'testimonials_custom_init' );