我已经创建了自定义的帖子类型&;然而,当我转到我的分类页面时,它抛出了一个404错误,我不明白为什么。
// Register Custom Post Type
function portfolio_post_type() {
register_taxonomy_for_object_type(\'category\',\'portfolio\');
register_post_type( \'portfolio\',
array(
\'labels\' => array(
\'name\' => __(\'Portfolio\'),
\'singular_name\' => __(\'Portfolio\'),
\'add_new\' => __(\'Add new item\'),
\'add_new_item\' => __(\'Add new item\'),
\'edit\' => __(\'Edit\'),
\'edit_item\' => __(\'Edit item\'),
\'new_item\' => __(\'New item\'),
\'view\' => __(\'View item\'),
\'view_item\' => __(\'View item\'),
\'search_items\' => __(\'Search portfolio\'),
\'not_found\' => __(\'No portfolio items found\'),
\'not_found_in_trash\' => __(\'No portfolio items found in trash\'),
),
\'public\' => true,
\'rewrite\' => array(\'slug\' => \'portfolio\'),
\'publicly_queryable\' => true,
\'hierarchical\' => false,
\'has_archive\' => true,
\'menu_icon\' => \'dashicons-art\',
\'supports\' => array(\'title\', \'editor\', \'excerpt\', \'thumbnail\', \'revisions\',\'author\'),
\'can_export\' => true,
\'taxonomies\' => array(\'portfolio-category\'),
)
);
}
add_action( \'init\', \'portfolio_post_type\', 0 );
function portfolio_create_taxonomy() {
register_taxonomy(
\'portfolio-category\',
\'portfolio\',
array(
\'label\' => __( \'Category\' ),
\'rewrite\' => array( \'slug\' => \'category\' ),
\'hierarchical\' => true,
)
);
}
add_action( \'init\', \'portfolio_create_taxonomy\' );
当我单击查看分类法时
http://domain.local/category/all/
然而,它抛出了404页模板。
SO网友:nmr
鼻涕虫category
已在使用中。Reserved_Terms
更改后,打开“永久链接设置”页面并单击“保存”。
function portfolio_post_type() {
//register_taxonomy_for_object_type(\'category\',\'portfolio\');
register_post_type( \'portfolio\',
array(
\'labels\' => array(
\'name\' => __(\'Portfolio\'),
\'singular_name\' => __(\'Portfolio\'),
\'add_new\' => __(\'Add new item\'),
\'add_new_item\' => __(\'Add new item\'),
\'edit\' => __(\'Edit\'),
\'edit_item\' => __(\'Edit item\'),
\'new_item\' => __(\'New item\'),
\'view\' => __(\'View item\'),
\'view_item\' => __(\'View item\'),
\'search_items\' => __(\'Search portfolio\'),
\'not_found\' => __(\'No portfolio items found\'),
\'not_found_in_trash\' => __(\'No portfolio items found in trash\'),
),
\'public\' => true,
\'rewrite\' => array(\'slug\' => \'portfolio\'),
\'publicly_queryable\' => true,
\'hierarchical\' => false,
\'has_archive\' => true,
\'menu_icon\' => \'dashicons-art\',
\'supports\' => array(\'title\', \'editor\', \'excerpt\', \'thumbnail\', \'revisions\',\'author\'),
\'can_export\' => true,
\'taxonomies\' => array(\'portfolio-category\'),
)
);
}
add_action( \'init\', \'portfolio_post_type\');
function portfolio_create_taxonomy() {
register_taxonomy(
\'portfolio-category\',
\'portfolio\',
array(
\'label\' => __( \'Category\' ),
\'rewrite\' => array( \'slug\' => \'portfolio-category\' ), // changed from reserved "category" slug
\'hierarchical\' => true,
)
);
}
add_action( \'init\', \'portfolio_create_taxonomy\' );