【发布时间】:2015-08-19 07:23:03
【问题描述】:
我已经注册了一个自定义帖子类型 faq 和一个名为 cat_faq 的 faq 分类。我创建了一个名为taxonomy-cat_faq.php 的模板,但默认没有选中它。它始终显示 404 页面。我不明白为什么会这样?我读出了Template Hierarchy 并按如下方式工作,但未能找出错误。我附上了下面的代码
add_action('init', 'register_faq');
function register_faq(){
$post_type = 'faq';
$label = array(
'name' => _x('FAQ', 'FAQ', 'faq'),
'singular_name' => _x('FAQ', 'FAQ', 'faq'),
'menu_name' => _x('FAQ', 'admin menu', 'faq')
);
$args = array(
'labels' => $label,
'public' => true,
'rewrite' => array('slug' => 'faq'),
'capability' => 'post',
'supports' => array('title', 'editor', 'thumbnail'),
);
register_post_type($post_type, $args);
}
// create taxonomies for the post type "faq"
add_action( 'init', 'create_faq_taxonomies', 0 );
function create_faq_taxonomies() {
$labels = array(
'name' => _x( 'FAQ', 'taxonomy general name' ),
'singular_name' => _x( 'FAQ', 'taxonomy singular name' ),
'search_items' => __( 'Search FAQ' ),
'edit_item' => __( 'Edit FAQ' ),
'update_item' => __( 'Update FAQ' ),
'add_new_item' => __( 'Add New FAQ' ),
'new_item_name' => __( 'New FAQ' ),
'menu_name' => __( 'Category FAQ' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'cat_faq' ),
);
register_taxonomy( 'cat_faq', array( 'faq' ), $args );
}
【问题讨论】:
-
尝试刷新重写规则