我的问题可能不清楚/令人困惑,所以这里有一个我想做的例子。
我有一个自定义的食谱帖子类型和一个自定义的成分分类法。
下面的url很好用:mywebsite。com/食谱/配料/鱼/
现在我想要的是类似于网站的东西。com/recipes/components/显示不同分类法(成分)的列表。
但我刚拿到404。
有人也有类似的问题:Creating a page for custom taxonomy archive通过创建一个页面解决了这个问题。我已经创建了一个“配方”和“配料”页面,但在打开“/配方/配料”页面时仍然出现404错误(猜测是由于相同的鼻涕虫引起的某种冲突)。我还尝试了模板层次结构的不同选项(http://codex.wordpress.org/images/1/18/Template_Hierarchy.png), 但到目前为止没有任何运气。
我不确定它是否能工作,因为wordpress中也没有标准的“/类别/”页面。但也许有办法?
代码如下所示:
// Register Custom Taxonomy
function ingredients() {
$labels = array(
\'name\' => _x( \'ingredients\', \'Taxonomy General Name\', \'text_domain\' ),
\'singular_name\' => _x( \'ingredient\', \'Taxonomy Singular Name\', \'text_domain\' ),
\'menu_name\' => __( \'ingredients\', \'text_domain\' ),
\'all_items\' => __( \'All ingredients\', \'text_domain\' ),
\'parent_item\' => __( \'zz ingredient\', \'text_domain\' ),
\'parent_item_colon\' => __( \'zz ingredient:\', \'text_domain\' ),
\'new_item_name\' => __( \'new ingredient\', \'text_domain\' ),
\'add_new_item\' => __( \'ingredient hh\', \'text_domain\' ),
\'edit_item\' => __( \'ingredient bb\', \'text_domain\' ),
\'update_item\' => __( \'ingredients bb\', \'text_domain\' ),
\'separate_items_with_commas\' => __( \'ingredients sep\', \'text_domain\' ),
\'search_items\' => __( \'ingredients search\', \'text_domain\' ),
\'add_or_remove_items\' => __( \'ingredient add delete\', \'text_domain\' ),
\'choose_from_most_used\' => __( \'most used\', \'text_domain\' ),
\'not_found\' => __( \'not found\', \'text_domain\' ),
);
$rewrite = array(
\'slug\' => \'recipes/ingredients\',
\'with_front\' => true,
\'hierarchical\' => true,
);
$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,
\'exclude_from_search\' => false,
);
register_taxonomy( \'ingredients\', array( \'recipes\' ), $args );}
// Register Custom Post Type
function recipes_posts() {
$labels = array(
\'name\' => _x( \'recipes\', \'Post Type General Name\', \'text_domain\' ),
\'singular_name\' => _x( \'recipe\', \'Post Type Singular Name\', \'text_domain\' ),
\'menu_name\' => __( \'recipes\', \'text_domain\' ),
\'parent_item_colon\' => __( \'Übergeordnete recipe:\', \'text_domain\' ),
\'all_items\' => __( \'All recipes\', \'text_domain\' ),
\'view_item\' => __( \'recipe cc\', \'text_domain\' ),
\'add_new_item\' => __( \'recipe bb\', \'text_domain\' ),
\'add_new\' => __( \'ww hinzufügen\', \'text_domain\' ),
\'edit_item\' => __( \'recipe zz\', \'text_domain\' ),
\'update_item\' => __( \'recipe uu\', \'text_domain\' ),
\'search_items\' => __( \'recipe ss\', \'text_domain\' ),
\'not_found\' => __( \'not found\', \'text_domain\' ),
\'not_found_in_trash\' => __( \'nf trash\', \'text_domain\' ),
);
$rewrite = array(
\'slug\' => \'recipes\',
\'with_front\' => true,
\'pages\' => true,
\'feeds\' => true,
);
$args = array(
\'label\' => __( \'recipes\', \'text_domain\' ),
\'description\' => __( \'div. recipes.\', \'text_domain\' ),
\'labels\' => $labels,
\'supports\' => array( \'title\', \'editor\', \'thumbnail\', \'comments\', ),
\'hierarchical\' => false,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_position\' => 10,
\'menu_icon\' => \'\',
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'rewrite\' => $rewrite,
\'capability_type\' => \'post\',
);
register_post_type( \'recipes\', $args );}