我试图为我的网站的每个部分创建不同的帖子类型,但我卡住了。
这是我目前为止写的:
function create_post_type() {
register_post_type( 'information',
array(
'labels' => array(
'name' => __( 'Information' ),
'singular_name' => __( 'Information' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'information'),
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt' ),
'menu_icon' => 'dashicons-admin-post',
)
);
}
add_action( 'init', 'create_post_type' );
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
register_taxonomy(
'information',
'information',
array(
'hierarchical' => true,
'label' => 'Type',
'query_var' => 'information',
'rewrite' => array( 'slug' => 'type' )
)
);
}
显示在面板的左侧栏Information/Add new/Type
在我的网站上,我看到了我注册的所有"类型"的帖子和侧边栏。
我需要看,例如:
mywebsite.com/information/daily ->列出以每日分类法标记的信息中的所有帖子。
,是:mywebsite.com/customposttype/taxonomy
实际上我有一个带有循环的taxonomy-information.php,但它将我发送到主页(尝试了taxonomy-type.php, taxonomy-information-type.php,没有一个工作)。
我做错了什么?
首先尝试重新保存你的永久链接结构(并确保wordpress有权限更改你的根目录下的。htaccess文件)。
第二,我不认为这是一个很好的主意,既命名的帖子类型和分类法相同,然后重命名它的鼻涕虫…这样做有什么好的理由吗?