admin管理员组文章数量:1122832
Edit: Now I've found that this is Hybrid Core, and apparently the template hierarchy is different. I still haven't solved my problem below though.
In addition to the title. My thinking is that if I am able to select a template in the backend, it should honor that selection. It doesn't change though. I've tested the other template file in place of the default, and it works.
This is the function to add my custom post type. This works just fine.
add_action( 'init', 'register_cpt_location' );
function register_cpt_location() {
$labels = array(
'name' => _x( 'Locations', 'info_location' ),
'singular_name' => _x( 'Location', 'info_location' )
);
$args = array(
'labels' => $labels,
'description' => 'Custom Post Type for Location',
'hierarchical' => true,
'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields', 'revisions', 'page-attributes' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 6,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => true,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => array(
'slug' => 'location',
'with_front' => false,
'feeds' => true,
'pages' => true
),
'menu_icon' => 'dashicons-location',
'capability_type' => 'post'
);
register_post_type( 'info_location', $args );
}
When I add a template for the custom post type (only to use on a few posts), the metabox shows up with my new template. However, the live page still uses the default template for the custom post type.
The default template is "info_location.php".
This is my head info for the template file "info_location-fm.php".
/*
* Template Name: Location-fm
* Template Post Type: info_location
*/
showing the drop down for templates (below)
new template selected and saved, still doesn't work (below)
Edit: Now I've found that this is Hybrid Core, and apparently the template hierarchy is different. I still haven't solved my problem below though.
In addition to the title. My thinking is that if I am able to select a template in the backend, it should honor that selection. It doesn't change though. I've tested the other template file in place of the default, and it works.
This is the function to add my custom post type. This works just fine.
add_action( 'init', 'register_cpt_location' );
function register_cpt_location() {
$labels = array(
'name' => _x( 'Locations', 'info_location' ),
'singular_name' => _x( 'Location', 'info_location' )
);
$args = array(
'labels' => $labels,
'description' => 'Custom Post Type for Location',
'hierarchical' => true,
'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields', 'revisions', 'page-attributes' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 6,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => true,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => array(
'slug' => 'location',
'with_front' => false,
'feeds' => true,
'pages' => true
),
'menu_icon' => 'dashicons-location',
'capability_type' => 'post'
);
register_post_type( 'info_location', $args );
}
When I add a template for the custom post type (only to use on a few posts), the metabox shows up with my new template. However, the live page still uses the default template for the custom post type.
The default template is "info_location.php".
This is my head info for the template file "info_location-fm.php".
/*
* Template Name: Location-fm
* Template Post Type: info_location
*/
showing the drop down for templates (below)
new template selected and saved, still doesn't work (below)
Share Improve this question edited Aug 11, 2017 at 21:09 Will Braden asked Aug 11, 2017 at 14:18 Will BradenWill Braden 13 bronze badges1 Answer
Reset to default 0in your code:
$labels = array(
'name' => _x( 'Locations', 'info_locaiton' ),
'singular_name' => _x( 'Location', 'info_location' )
);
use this:
$labels = array(
'name' => _x( 'Locations', 'info_location' ),
'singular_name' => _x( 'Location', 'info_location' )
);
In $labels variable name array value has different slug. I think this can be a problem. So, you can correct it and check. Or you can use custom post type plugin to make custom post type easily.
Hope this will help!
本文标签:
版权声明:本文标题:Wordpress Custom Post Type - Post Attribute: Template. Template shows up and saves on the back end, but the default theme file i 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736281902a1926471.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论