Custom Post Type Permalink

时间:2014-03-29 作者:Jaeeun Lee

我有一个名为“Emily Davies”、“Gemma Patel”和“Poppy Smythe”的自定义帖子类型,我想通过访问“../Emily\\u Davies”“…/Gemma\\u Patel”和“../Poppy\\u Smythe”访问其档案。Emily Davies可以工作,但由于某种原因后两个不行。他们只显示了404错误。我有档案——emily\\u davies。php,archive-gemma\\u patel。php,abd archive-poppy\\u smythe。php。

我的函数中有此代码。php,并且我的permalink设置设置为“/%类别%/%postname%/”

add_action( \'init\', \'create_post_type\' );
function create_post_type(){

register_post_type( \'emily_davies\',
array(
\'labels\' => array(
     \'name\' => __(\'Emily Davies\'),
     \'singular_name\' => __(\'Post\'),
     \'add_new\' => __(\'Add New\'),
     \'add_new_item\' => __(\'Add New Post\'),
     \'edit_item\' => __(\'Edit Post\'),
     \'new_item\' => __(\'New Post\'),
     \'all_items\' => __(\'All Posts\'),
     \'view_item\' => __(\'View Posts\'),
     \'search_items\' => __(\'Search Posts\'),
     \'not_found\' =>  __(\'No Posts found\'),
     \'not_found_in_trash\' => __(\'No Posts found in Trash\'), 
     \'parent_item_colon\' => \'\',
     \'menu_name\' => \'Emily Davies\'
    ),
\'rewrite\' => true,
\'publicly_queryable\' => true,
\'public\' => true,
\'show_ui\' => true,
\'hierarchical\' => false,
\'menu_position\' => 5,
\'query_var\' => true,
\'has_archive\' =>true,
\'supports\' => array(\'title\',\'editor\',\'thumbnail\',\'excerpt\',\'comments\',)
 )
 ); 
$labels = array(
\'name\' => _x(\'Categories\', \'taxonomy general name\' ),
\'singular_name\' => _( \'Category\'),
\'search_items\' =>  __( \'Search Category\' ),
\'popular_items\' => __( \'Popular Categories\' ),
\'all_items\' => __( \'All Categories\' ),
\'parent_item\' => null,
\'parent_item_colon\' => null,
\'edit_item\' => __( \'Edit Category\' ), 
\'update_item\' => __( \'Update Category\' ),
\'add_new_item\' => __( \'Add New Category\' ),
\'new_item_name\' => __( \'New Category Name\' ),
\'separate_items_with_commas\' => __( \'Separate Category with commas\' ),
\'add_or_remove_items\' => __( \'Add or remove Categories\' ),
\'choose_from_most_used\' => __( \'Choose from the most used Categories\' ),
\'menu_name\' => __( \'Categories\' ),
 ); 
register_taxonomy(\'emily_category\',\'emily_davies\',array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'emily-category\' ),
  ));

register_post_type( \'poppy_smythe\',
array(
\'labels\' => array(
     \'name\' => __(\'Poppy Smythe\'),
     \'singular_name\' => __(\'Post\'),
     \'add_new\' => __(\'Add New\'),
     \'add_new_item\' => __(\'Add New Post\'),
     \'edit_item\' => __(\'Edit Post\'),
     \'new_item\' => __(\'New Post\'),
     \'all_items\' => __(\'All Posts\'),
     \'view_item\' => __(\'View Posts\'),
     \'search_items\' => __(\'Search Posts\'),
     \'not_found\' =>  __(\'No Posts found\'),
     \'not_found_in_trash\' => __(\'No Posts found in Trash\'), 
     \'parent_item_colon\' => \'\',
     \'menu_name\' => \'Poppy Smythe\'
    ),
\'rewrite\' => true,
\'publicly_queryable\' => true,
\'public\' => true,
\'show_ui\' => true,
\'hierarchical\' => false,
\'menu_position\' => 5,
\'query_var\' => true,
\'has_archive\' =>true,
\'supports\' => array(\'title\',\'editor\',\'thumbnail\',\'excerpt\',\'comments\',)
)
 ); 
 $labels = array(
\'name\' => _x(\'Categories\', \'taxonomy general name\' ),
\'singular_name\' => _( \'Category\'),
\'search_items\' =>  __( \'Search Category\' ),
\'popular_items\' => __( \'Popular Categories\' ),
\'all_items\' => __( \'All Categories\' ),
\'parent_item\' => null,
\'parent_item_colon\' => null,
\'edit_item\' => __( \'Edit Category\' ), 
\'update_item\' => __( \'Update Category\' ),
\'add_new_item\' => __( \'Add New Category\' ),
\'new_item_name\' => __( \'New Category Name\' ),
\'separate_items_with_commas\' => __( \'Separate Category with commas\' ),
\'add_or_remove_items\' => __( \'Add or remove Categories\' ),
\'choose_from_most_used\' => __( \'Choose from the most used Categories\' ),
\'menu_name\' => __( \'Categories\' ),
 ); 
 register_taxonomy(\'popy_category\',\'poppy_smythe\',array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'poppy-category\' ),
 ));

 register_post_type( \'gemma_patel\',
 array(
\'labels\' => array(
     \'name\' => __(\'Gemma Patel\'),
     \'singular_name\' => __(\'Post\'),
     \'add_new\' => __(\'Add New\'),
     \'add_new_item\' => __(\'Add New Post\'),
     \'edit_item\' => __(\'Edit Post\'),
     \'new_item\' => __(\'New Post\'),
     \'all_items\' => __(\'All Posts\'),
     \'view_item\' => __(\'View Posts\'),
     \'search_items\' => __(\'Search Posts\'),
     \'not_found\' =>  __(\'No Posts found\'),
     \'not_found_in_trash\' => __(\'No Posts found in Trash\'), 
     \'parent_item_colon\' => \'\',
     \'menu_name\' => \'Gemma Patel\'
    ),
\'rewrite\' => true,
\'publicly_queryable\' => true,
\'public\' => true,
\'show_ui\' => true,
\'hierarchical\' => false,
\'menu_position\' => 5,
\'query_var\' => true,
\'has_archive\' =>true,
\'supports\' => array(\'title\',\'editor\',\'thumbnail\',\'excerpt\',\'comments\',)
)
); 
$labels = array(
\'name\' => _x(\'Categories\', \'taxonomy general name\' ),
\'singular_name\' => _( \'Category\'),
\'search_items\' =>  __( \'Search Category\' ),
\'popular_items\' => __( \'Popular Categories\' ),
\'all_items\' => __( \'All Categories\' ),
\'parent_item\' => null,
\'parent_item_colon\' => null,
\'edit_item\' => __( \'Edit Category\' ), 
\'update_item\' => __( \'Update Category\' ),
\'add_new_item\' => __( \'Add New Category\' ),
\'new_item_name\' => __( \'New Category Name\' ),
\'separate_items_with_commas\' => __( \'Separate Category with commas\' ),
\'add_or_remove_items\' => __( \'Add or remove Categories\' ),
\'choose_from_most_used\' => __( \'Choose from the most used Categories\' ),
\'menu_name\' => __( \'Categories\' ),
); 
 register_taxonomy(\'gemma_category\',\'gemma_patel\',array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'gemma-category\' ),
 ));
 }  

1 个回复
最合适的回答,由SO网友:Scott S 整理而成

你试过刷新永久链接吗?

访问permalinks页面,点击save-如果CPT在其他方面都正常工作,这应该可以解决问题。

结束

相关推荐

Advanced permalinks structure

我想得到这个:mysite.com/category/tag/ 示例:mysite.com/news/sports/ 新闻是一个类别,体育是一个标签我该怎么做?谢谢