我想对页面上不同类型的帖子使用自定义帖子类型和自定义分类法。我已经注册了一个名为“portfolio”的自定义帖子类型和该帖子类型的分类法。
function my_custom_post_portfolio() {
$labels = array(
\'name\' => _x( \'Portfolio\', \'post type general name\' ),
\'singular_name\' => _x( \'Portfolio-item\', \'post type singular name\' ),
\'add_new\' => _x( \'Add New\', \'portfolio\' ),
\'add_new_item\' => __( \'Add New Item\' ),
\'edit_item\' => __( \'Edit Item\' ),
\'new_item\' => __( \'New Item\' ),
\'all_items\' => __( \'All Items\' ),
\'view_item\' => __( \'View Item\' ),
\'search_items\' => __( \'Search Items\' ),
\'not_found\' => __( \'No items found\' ),
\'not_found_in_trash\' => __( \'No items found in the Trash\' ),
\'parent_item_colon\' => \'\',
\'menu_name\' => \'Portfolio\'
);
$args = array(
\'labels\' => $labels,
\'description\' => \'Holds our portfolio items\',
\'public\' => true,
\'menu_position\' => 5,
\'supports\' => array( \'title\', \'editor\', \'thumbnail\', \'excerpt\', \'comments\' ),
\'taxonomies\' => array(\'category\'),
\'has_archive\' => true,
);
register_post_type( \'portfolio\', $args );
}
add_action( \'init\', \'my_custom_post_portfolio\' );
function add_custom_taxonomies() {
register_taxonomy(\'portfolioitems\', \'portfolio\', array(
\'hierarchical\' => true,
\'labels\' => array(
\'name\' => _x( \'Portfolioitems\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Item\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search items\' ),
\'all_items\' => __( \'All items\' ),
\'parent_item\' => __( \'Parent item\' ),
\'parent_item_colon\' => __( \'Parent item:\' ),
\'edit_item\' => __( \'Edit item\' ),
\'update_item\' => __( \'Update item\' ),
\'add_new_item\' => __( \'Add new item\' ),
\'new_item_name\' => __( \'New item name\' ),
\'menu_name\' => __( \'items\' ),
),
\'rewrite\' => array(
\'slug\' => \'portfolio\',
\'with_front\' => false,
\'hierarchical\' => true
),
));
}
add_action( \'init\', \'add_custom_taxonomies\', 0 );
我有他们两个的模板文件,一个归档文件包。php,公文包帖子的“起始页”,一个公文包。php用于显示单个投资组合项目,以及一个分类组合项目。php,用于显示与一个“标记”相关的所有帖子(技术上是一个自定义分类项目)
它现在工作得很好,只是我在查看公文包帖子时得到了404。我的permalink结构是:
/%类别%/%postname%/
我还激活了FV顶级分类插件,可以从url中删除“分类”(如/category/portfolio/portfolio post)。
当我尝试查看我的“普通”博客帖子时,其工作正常,url为/blog/blog categoryname/post name
但是我的自定义帖子类型项目在尝试调用/自定义帖子类型/帖子名称时给我404
(我还有一个名为“portfolio”的菜单链接,它指向类别portfolio,该类别portfolio是用自定义帖子类型注册的。这会不会有什么影响?)
非常感谢!