我从一个新模板开始,添加了Post Type
根据规范GenerateWP.
然后,我向自定义帖子类型添加了一个分类法,也根据上面引用的网站:
// Register Custom Taxonomy
function addIssuesTaxonomy() {
$labels = array(
\'name\' => _x( \'Issues\', \'Taxonomy General Name\', \'text_domain\' ),
\'singular_name\' => _x( \'Issue\', \'Taxonomy Singular Name\', \'text_domain\' ),
\'menu_name\' => __( \'Issues\', \'text_domain\' ),
\'all_items\' => __( \'All Issues\', \'text_domain\' ),
\'parent_item\' => __( \'Parent Issue\', \'text_domain\' ),
\'parent_item_colon\' => __( \'Parent Issue:\', \'text_domain\' ),
\'new_item_name\' => __( \'New Issue Name\', \'text_domain\' ),
\'add_new_item\' => __( \'Add New Issue\', \'text_domain\' ),
\'edit_item\' => __( \'Edit Issue\', \'text_domain\' ),
\'update_item\' => __( \'Update Issue\', \'text_domain\' ),
\'view_item\' => __( \'View Issue\', \'text_domain\' ),
\'separate_items_with_commas\' => __( \'Separate issues with commas\', \'text_domain\' ),
\'add_or_remove_items\' => __( \'Add or remove issues\', \'text_domain\' ),
\'choose_from_most_used\' => __( \'Choose from the most used\', \'text_domain\' ),
\'popular_items\' => __( \'Popular Issues\', \'text_domain\' ),
\'search_items\' => __( \'Search Issues\', \'text_domain\' ),
\'not_found\' => __( \'Not Found\', \'text_domain\' ),
\'no_terms\' => __( \'No items\', \'text_domain\' ),
\'items_list\' => __( \'Issues list\', \'text_domain\' ),
\'items_list_navigation\' => __( \'Issues list navigation\', \'text_domain\' ),
);
$rewrite = array(
\'slug\' => \'issues\',
\'with_front\' => true,
\'hierarchical\' => false,
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'show_in_nav_menus\' => true,
\'show_tagcloud\' => true,
\'rewrite\' => $rewrite,
);
register_taxonomy( \'issues\', array( \'articles\' ), $args );
}
add_action( \'init\', \'addIssuesTaxonomy\', 0 );
然后我将永久链接保存在此结构中
http://xxx/sample-post/
, 但无论如何,新添加的分类法不会出现在
http://xxx/issues
. 相反,我得到了404。导航到
/articles/issues/
也导致404。
为了显示所有issues
在新创建的分类中找到?