【发布时间】:2016-02-04 22:38:52
【问题描述】:
我正在 wordpress 网站上建立一个常见问题解答部分。我有一个名为 faq 的自定义帖子类型,它有一个名为 faq-category 的自定义分类。我还使用了一个名为 Custom Post Type Permalinks 的插件。
我正在尝试实现以下永久链接结构:
- domain.com/faq
- domain.com/faq/category
- domain.com/faq/category/question-title
到目前为止,我似乎只能完成 2/3 的工作。所以下面的例子给了我:
- domain.com/faq
- domain.com/faq/category
和 `domain.com/faq/category/question-title 上的 404
如果我改变:'slug' => 'faq' 到 'slug' => '' 我重写的自定义分类。我在分类页面上收到 404 错误,并且单个帖子可以正常工作。
谢谢
/**
* Custom taxonomys
*/
function create_faq_tax() {
register_taxonomy(
'faq-category',
'faq',
array(
'label' => __( 'Category' ),
'rewrite' => array( 'slug' => 'faq', 'with_front' => false, 'hierarchical' => true ),
'hierarchical' => true
)
);
}
add_action( 'init', 'create_faq_tax' );
/**
* FAQ Custom post type
*/
function create_faq_post_type() {
register_post_type( 'faq',
array(
'labels' => array(
'name' => __( 'FAQ\'s' ),
'singular_name' => __( 'FAQ' ),
'add_new' => 'Add new FAQ',
'add_new_item' => 'Add a new FAQ',
'edit_item' => 'Edit FAQ',
),
'public' => true,
'publicly_queryable' => true,
'hierarchical' => true,
'taxonomies' => array('faq-category'),
'has_archive' => true,
'menu_icon' => 'dashicons-feedback',
'rewrite' => array( 'slug' => 'faq', 'with_front' => false ),
'query_var' => true,
)
);
}
add_action( 'init', 'create_faq_post_type' );
【问题讨论】:
-
我自己的自定义帖子类型(啤酒)和类似的分类法(啤酒/风格)遇到了同样的问题。如果我将 slug 设置为
beer/style它会抛出 404,但如果我将 slug 设置为style税收页面可以工作,尽管不是我想要的永久链接结构。
标签: wordpress custom-post-type permalinks custom-taxonomy