我正在尝试创建一个自定义帖子类型(doctors),它将加载一个自定义页面模板(single doctors.php)。我已经通过函数设置了自定义帖子类型。php,并创建了一个“新医生”,选择了单个医生模板。但是,当我去实际查看页面时,模板不会加载,我会看到一个“未找到此页面”页面。我一直在搜索互联网,试图找到解决方案。我发现了很多相同的东西(刷新永久链接、删除“has\\u archive”等),但都不起作用。
作为一种解决方法,我尝试下载一个自定义帖子插件(自定义帖子类型UI)并以这种方式进行设置。这奏效了!!但我将在未来的网站上做更多的自定义帖子创建,并希望能够在没有插件的情况下做到这一点。我尝试使用插件本身生成的代码,并在函数中用它们的代码替换我的代码。php文件。这不起作用,我回到了“找不到页面”页面。我在拔头发。有人能帮我找出我遗漏了什么拼图吗?非常感谢您的帮助。我的职能。下面是php代码和插件代码。。。
我的代码:
// Doctors
add_action( \'init\', \'doctors_init\' );
function doctors_init() {
$labels = array(
\'name\' => _x( \'Doctors\', \'post type general name\', \'AIN\' ),
\'singular_name\' => _x( \'Doctor\', \'post type singular name\', \'AIN\' ),
\'menu_name\' => _x( \'Doctors\', \'admin menu\', \'AIN\' ),
\'name_admin_bar\' => _x( \'Doctor\', \'add new on admin bar\', \'AIN\' ),
\'add_new\' => _x( \'Add New\', \'Doctor\', \'AIN\' ),
\'add_new_item\' => __( \'Add New Doctor\', \'AIN\' ),
\'new_item\' => __( \'New Doctor\', \'AIN\' ),
\'edit_item\' => __( \'Edit Doctor\', \'AIN\' ),
\'view_item\' => __( \'View Doctor\', \'AIN\' ),
\'all_items\' => __( \'All Doctors\', \'AIN\' ),
\'search_items\' => __( \'Search Doctors\', \'AIN\' ),
\'parent_item_colon\' => __( \'Parent Doctors:\', \'AIN\' ),
\'not_found\' => __( \'No Doctors found.\', \'AIN\' ),
\'not_found_in_trash\' => __( \'No Doctors found in Trash.\', \'AIN\' )
);
$args = array(
"label" => __( "doctors", "understrap-child" ),
\'labels\' => $labels,
\'description\' => __( \'Description.\', \'AIN\' ),
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'doctors\', "with_front" => true ),
\'capability_type\' => \'post\',
\'has_archive\' => false,
\'hierarchical\' => false,
\'menu_position\' => null,
\'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\' ),
\'menu_icon\' => \'dashicons-groups\',
);
register_post_type( \'doctors\', $args );
}
插件代码:
function cptui_register_my_cpts_doctors2() {
/**
* Post Type: doctors2.
*/
$labels = array(
"name" => __( "doctors2", "understrap-child" ),
"singular_name" => __( "doctor2", "understrap-child" ),
);
$args = array(
"label" => __( "doctors2", "understrap-child" ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => false,
"rest_base" => "",
"has_archive" => false,
"show_in_menu" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "doctors2", "with_front" => true ),
"query_var" => true,
"supports" => array( "title", "editor", "thumbnail" ),
);
register_post_type( "doctors2", $args );
}
add_action( \'init\', \'cptui_register_my_cpts_doctors2\' );
非常感谢您的帮助或指导。谢谢