自定义邮寄类型档案/类别提供404

时间:2015-02-27 作者:Alex Chastain

我有一个客户想要一个博客、一个新闻版面和一个“更多帖子”版面来发布感觉良好的社区服务类帖子。我在博客中使用了标准的帖子类型,一切都很好。我用这个代码注册了另外两个帖子类型,这个代码在custom_posts(); 我添加的函数add_action( \'init\', \'custom_posts\');

register_post_type( \'press\',
    // let\'s now add all the options for this post type
    array( \'labels\' => array(
        \'name\' => __( \'Press\', \'bonestheme\' ),
        \'singular_name\' => __( \'Press\', \'bonestheme\' ),
        \'all_items\' => __( \'All Press\', \'bonestheme\' ),
        \'add_new\' => __( \'Add New\', \'bonestheme\' ),
        \'add_new_item\' => __( \'Add New Post\', \'bonestheme\' ), 
        \'edit\' => __( \'Edit\', \'bonestheme\' ),
        \'edit_item\' => __( \'Edit Post\', \'bonestheme\' ),
        \'new_item\' => __( \'New Post\', \'bonestheme\' ), 
        \'view_item\' => __( \'View Post\', \'bonestheme\' ), 
        \'search_items\' => __( \'Search Posts\', \'bonestheme\' ),  
        \'not_found\' =>  __( \'Nothing found in the Database.\', \'bonestheme\' ), 
        \'not_found_in_trash\' => __( \'Nothing found in Trash\', \'bonestheme\' ), 
        \'parent_item_colon\' => \'\'
        ), 
        \'description\' => __( \'Press\', \'bonestheme\' ), 
        \'public\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'show_ui\' => true,
        \'query_var\' => true,
        \'menu_position\' => 8, 
        \'rewrite\'   => array( \'slug\' => \'press-posts\' ),
        \'has_archive\' => true, 
        \'capability_type\' => \'post\',
        \'hierarchical\' => false,
        \'supports\' => array( \'title\', \'thumbnail\', \'excerpt\', \'revisions\', \'sticky\', \'custom-fields\', \'editor\', \'author\' )
    )
);

register_post_type( \'more_posts\',
    array( \'labels\' => array(
        \'name\' => __( \'More Posts\', \'bonestheme\' ),
        \'singular_name\' => __( \'Post\', \'bonestheme\' ),
        \'all_items\' => __( \'All Posts\', \'bonestheme\' ),
        \'add_new\' => __( \'Add New\', \'bonestheme\' ),
        \'add_new_item\' => __( \'Add New Post\', \'bonestheme\' ), 
        \'edit\' => __( \'Edit\', \'bonestheme\' ),
        \'edit_item\' => __( \'Edit Post\', \'bonestheme\' ),
        \'new_item\' => __( \'New Post\', \'bonestheme\' ),
        \'view_item\' => __( \'View Post\', \'bonestheme\' ),
        \'search_items\' => __( \'Search Posts\', \'bonestheme\' ),
        \'not_found\' =>  __( \'Nothing found in the Database.\', \'bonestheme\' ), 
        \'not_found_in_trash\' => __( \'Nothing found in Trash\', \'bonestheme\' ),
        \'parent_item_colon\' => \'\'
        ),
        \'description\' => __( \'More Posts\', \'bonestheme\' ), 
        \'public\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => true,
        \'show_ui\' => true,
        \'query_var\' => true,
        \'menu_position\' => 9,  
        \'rewrite\'   => array( \'slug\' => \'more-posts\' ),
        \'has_archive\' => true, 
        \'capability_type\' => \'post\',
        \'hierarchical\' => false,
        \'supports\' => array( \'title\', \'thumbnail\', \'excerpt\', \'revisions\', \'sticky\', \'custom-fields\', \'editor\', \'author\' ),
    )
);
我正在使用此代码添加分类法,也在custom_posts(); 功能:

    register_taxonomy( \'press_cat\', 
    array(\'press\'), /* if you change the name of register_post_type( \'press\', then you have to change this */
    array(\'hierarchical\' => true,     /* if this is true, it acts like categories */
        \'labels\' => array(
            \'name\' => __( \'Categories\', \'bonestheme\' ), /* name of the custom taxonomy */
            \'singular_name\' => __( \'Press Category\', \'bonestheme\' ), /* single taxonomy name */
            \'search_items\' =>  __( \'Search Press Categories\', \'bonestheme\' ), /* search title for taxomony */
            \'all_items\' => __( \'All Press Categories\', \'bonestheme\' ), /* all title for taxonomies */
            \'parent_item\' => __( \'Parent Press Category\', \'bonestheme\' ), /* parent title for taxonomy */
            \'parent_item_colon\' => __( \'Parent Press Category:\', \'bonestheme\' ), /* parent taxonomy title */
            \'edit_item\' => __( \'Edit Press Category\', \'bonestheme\' ), /* edit custom taxonomy title */
            \'update_item\' => __( \'Update Press Category\', \'bonestheme\' ), /* update title for taxonomy */
            \'add_new_item\' => __( \'Add New Press Category\', \'bonestheme\' ), /* add new title for taxonomy */
            \'new_item_name\' => __( \'New Press Category Name\', \'bonestheme\' ) /* name title for taxonomy */
        ),
        \'show_admin_column\' => true, 
        \'show_ui\' => true,
        \'query_var\' => true,
        \'rewrite\' => array( \'slug\' => \'press-posts-category\' )
    )
);
register_taxonomy( \'more_cat\', 
    array(\'more_posts\'), /* if you change the name of register_post_type( \'more-posts\', then you have to change this */
    array(\'hierarchical\' => true,     /* if this is true, it acts like categories */
        \'labels\' => array(
            \'name\' => __( \'Categories\', \'bonestheme\' ), /* name of the custom taxonomy */
            \'singular_name\' => __( \'Post Category\', \'bonestheme\' ), /* single taxonomy name */
            \'search_items\' =>  __( \'Search Posts Categories\', \'bonestheme\' ), /* search title for taxomony */
            \'all_items\' => __( \'All Posts Categories\', \'bonestheme\' ), /* all title for taxonomies */
            \'parent_item\' => __( \'Parent Posts Category\', \'bonestheme\' ), /* parent title for taxonomy */
            \'parent_item_colon\' => __( \'Parent Posts Category:\', \'bonestheme\' ), /* parent taxonomy title */
            \'edit_item\' => __( \'Edit Posts Category\', \'bonestheme\' ), /* edit custom taxonomy title */
            \'update_item\' => __( \'Update Posts Category\', \'bonestheme\' ), /* update title for taxonomy */
            \'add_new_item\' => __( \'Add New Posts Category\', \'bonestheme\' ), /* add new title for taxonomy */
            \'new_item_name\' => __( \'New Posts Category Name\', \'bonestheme\' ) /* name title for taxonomy */
        ),
        \'show_admin_column\' => true, 
        \'show_ui\' => true,
        \'query_var\' => true,
        \'rewrite\' => array( \'slug\' => \'more-posts-category\' )
    )
);
Press - 使用自定义permalinks时,存档被破坏(404)(可与std perma配合使用)

More - 使用自定义permalinks时,存档被破坏(404)(可与std perma配合使用)

More - category给了我一个页面,但没有返回任何帖子(其中有2篇帖子)

我正在使用this 插件在侧边栏上创建存档和类别列表,它似乎运行正常。它提供给我的URL是:

/新闻/2015/02/-新闻档案

/more\\u posts/2015/02/-更多存档

/更多帖子类别/回馈/-更多类别

1 个回复
SO网友:Milo

自定义post类型存档没有年/月重写规则,它们只有一个存档,该存档将位于/press//more_posts/. 如果你想要这些,你必须add them yourself. 对于分类法,添加taxonomies 参数来确保这两个对象是连接的,请参见register_post_type.

结束

相关推荐

Show all sub categories?

是否可以显示所有父猫的所有子/子类别?我有以下层次结构:父类别/税--子1--子2父类别/税2--子1--子2我想能够在一个模板上显示所有子类别,而不显示父类别。这可能吗?