我在WordPress中设置了一个自定义帖子类型(以下代码),主题中有一个archive-team.php,但是当我访问example.com/meet-the-team/时,它没有使用存档模板
它以前可以工作,但是不再起作用,它仅使用page.php模板。
function cptui_register_my_cpts_team() {
/**
* Post Type: Team Members.
*/
$labels = array(
"name" => __( "Team Members", "" ),
"singular_name" => __( "Team Member", "" ),
);
$args = array(
"label" => __( "Team Members", "" ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => false,
"rest_base" => "",
"has_archive" => "meet-the-team",
"show_in_menu" => true,
"show_in_nav_menus" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "team", "with_front" => true ),
"query_var" => true,
"menu_icon" => "dashicons-groups",
"supports" => array( "title", "page-attributes" ),
);
register_post_type( "team", $args );
}
add_action( 'init', 'cptui_register_my_cpts_team' );
我已经刷新了永久链接,并尝试重新添加CPT,但没有任何乐趣。
答案 0 :(得分:0)
"has_archive" => "meet-the-team",
是错误的。根据{{3}},它应该是布尔值或可翻译的。同样,正如M Hayward所说,如果您要让归档文件成为团队成员,则该文件必须是归档模板的文件名。
答案 1 :(得分:0)
谢谢您的帮助/建议,但我设法解决了该问题。
我更改了以下内容:
"rewrite" => array( "slug" => "team", "with_front" => true ),
对此:
"rewrite" => array( "slug" => "team", "with_front" => false ),
因此完整的CPT寄存器功能如下:
function cptui_register_my_cpts_team() {
/**
* Post Type: Team Members.
*/
$labels = array(
"name" => __( "Team Members", "" ),
"singular_name" => __( "Team Member", "" ),
);
$args = array(
"label" => __( "Team Members", "" ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => false,
"rest_base" => "",
"has_archive" => "meet-the-team",
"show_in_menu" => true,
"show_in_nav_menus" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "team", "with_front" => false ),
"query_var" => true,
"menu_icon" => "dashicons-groups",
"supports" => array( "title", "page-attributes" ),
);
register_post_type( "team", $args );
}
add_action( 'init', 'cptui_register_my_cpts_team' );
这正在使用archive-team.php