我已经为帖子配置了permastructure/blog/%postname%/
, 我用slug创建了一个页面about-us
我用下面的代码注册team_member
CPT正在运行。我想你在重写的争论中多了一个“/”。此外,您不需要与global $wp_rewrite
; 如果在注册post类型时设置重写参数,WordPress将为您创建重写规则。为了保存不需要的代码,我也发表了一些评论:
add_action("init", "register_cpt_team_member");
function register_cpt_team_member() {
$labels = array(
//If "label" is set, the "name" in "labels" argument is usually not needed
//\'name\' => _x( \'Team Members\', \'Post Type General Name\', \'client\' ),
// [...]
);
$args = array(
//label should a plural descriptive name
\'label\' => __( \'Team Members\', \'client\' ),
//description should include ...... a description ;)
\'description\' => __( \'Custom post type to manage team members\', \'client\' ),
//As the only "labels" set was "name" and it overriden by general "label" you don\'t need this
//\'labels\' => $labels,
\'supports\' => array( \'title\', \'editor\', \'thumbnail\' ),
//hierarchical is by default false, you don\'t need this
//\'hierarchical\' => false,
\'public\' => true,
//show_ui is by default set to same value of "public", so you don\'t need this
//\'show_ui\' => true,
//show_in_menu by default set to same value of "show_ui", so you don\'t need this
//\'show_in_menu\' => true,
//show_in_nav_menus is by default set to same value of "public", so you don\'t need this
//\'show_in_nav_menus\' => true,
//show_in_admin_bar by default set to same value of "show_in_menu", so you don\'t need this
//\'show_in_admin_bar\' => true,
\'menu_position\' => 5,
//can_export is by default set to true, so you don\'t need this
//\'can_export\' => true,
\'has_archive\' => true,
//exclude_from_search is by default set to opposite of "public", so you don\'t need this
//\'exclude_from_search\' => false,
//publicly_queryable is by default set to same value of "public" argumente, so you don\'t need this
//\'publicly_queryable\' => true,
\'capability_type\' => \'page\',
\'rewrite\' => array (
\'slug\' => \'/about-us/team\',
\'with_front\' => false
)
);
register_post_type( \'team_member\', $args );
}
因此,可以这样编写上述代码,并得到相同的结果:
add_action("init", "register_cpt_team_member");
function register_cpt_team_member() {
$args = array(
\'label\' => __( \'Team Members\', \'client\' ),
\'description\' => __( \'Custom post type to manage team members\', \'client\' ),
\'supports\' => array( \'title\', \'editor\', \'thumbnail\' ),
\'public\' => true,
\'menu_position\' => 5,
\'has_archive\' => true,
\'capability_type\' => \'page\',
\'rewrite\' => array (
\'slug\' => \'/about-us/team\',
\'with_front\' => false
)
);
register_post_type( \'team_member\', $args );
}