admin管理员组文章数量:1130349
I have registered a custom post type and I am trying to make posts of that type display in a specific template file but can't figure out what to name my template file in order for the posts to use it.
Here's my code in my functions file:
function digital_post_type() {
register_post_type( 'digital',
array(
'labels' => array(
'name' => __( 'Digital Assets' ),
'singular_name' => __( 'Digital Asset' ),
'menu_name' => __( 'Digital'),
'name_admin_bar' => __( 'Digital Assets'),
'add_new' => __( 'Add New'),
'add_new_item' => __( 'Add New Digital Asset'),
'new_item' => __( 'New Digital Asset'),
'edit_item' => __( 'Edit Digital Asset'),
'view_item' => __( 'View Digital Asset'),
'all_items' => __( 'All Digital Assets')
),
'public' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => 'digital_assets' ),
'supports' => array( 'title','thumbnail', 'excerpt' )
)
);
}
add_action( 'init', 'digital_post_type' );
I tried naming my template file single-digital_assets.php but the posts are still using the default single.php template. I also tried resaving my permalink settings to make sure it wasn't a caching issue.
I have registered a custom post type and I am trying to make posts of that type display in a specific template file but can't figure out what to name my template file in order for the posts to use it.
Here's my code in my functions file:
function digital_post_type() {
register_post_type( 'digital',
array(
'labels' => array(
'name' => __( 'Digital Assets' ),
'singular_name' => __( 'Digital Asset' ),
'menu_name' => __( 'Digital'),
'name_admin_bar' => __( 'Digital Assets'),
'add_new' => __( 'Add New'),
'add_new_item' => __( 'Add New Digital Asset'),
'new_item' => __( 'New Digital Asset'),
'edit_item' => __( 'Edit Digital Asset'),
'view_item' => __( 'View Digital Asset'),
'all_items' => __( 'All Digital Assets')
),
'public' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => 'digital_assets' ),
'supports' => array( 'title','thumbnail', 'excerpt' )
)
);
}
add_action( 'init', 'digital_post_type' );
I tried naming my template file single-digital_assets.php but the posts are still using the default single.php template. I also tried resaving my permalink settings to make sure it wasn't a caching issue.
1 Answer
Reset to default 1The post type name is digital (register_post_type( 'digital',) so the template should be single-digital.php.
I have registered a custom post type and I am trying to make posts of that type display in a specific template file but can't figure out what to name my template file in order for the posts to use it.
Here's my code in my functions file:
function digital_post_type() {
register_post_type( 'digital',
array(
'labels' => array(
'name' => __( 'Digital Assets' ),
'singular_name' => __( 'Digital Asset' ),
'menu_name' => __( 'Digital'),
'name_admin_bar' => __( 'Digital Assets'),
'add_new' => __( 'Add New'),
'add_new_item' => __( 'Add New Digital Asset'),
'new_item' => __( 'New Digital Asset'),
'edit_item' => __( 'Edit Digital Asset'),
'view_item' => __( 'View Digital Asset'),
'all_items' => __( 'All Digital Assets')
),
'public' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => 'digital_assets' ),
'supports' => array( 'title','thumbnail', 'excerpt' )
)
);
}
add_action( 'init', 'digital_post_type' );
I tried naming my template file single-digital_assets.php but the posts are still using the default single.php template. I also tried resaving my permalink settings to make sure it wasn't a caching issue.
I have registered a custom post type and I am trying to make posts of that type display in a specific template file but can't figure out what to name my template file in order for the posts to use it.
Here's my code in my functions file:
function digital_post_type() {
register_post_type( 'digital',
array(
'labels' => array(
'name' => __( 'Digital Assets' ),
'singular_name' => __( 'Digital Asset' ),
'menu_name' => __( 'Digital'),
'name_admin_bar' => __( 'Digital Assets'),
'add_new' => __( 'Add New'),
'add_new_item' => __( 'Add New Digital Asset'),
'new_item' => __( 'New Digital Asset'),
'edit_item' => __( 'Edit Digital Asset'),
'view_item' => __( 'View Digital Asset'),
'all_items' => __( 'All Digital Assets')
),
'public' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => 'digital_assets' ),
'supports' => array( 'title','thumbnail', 'excerpt' )
)
);
}
add_action( 'init', 'digital_post_type' );
I tried naming my template file single-digital_assets.php but the posts are still using the default single.php template. I also tried resaving my permalink settings to make sure it wasn't a caching issue.
1 Answer
Reset to default 1The post type name is digital (register_post_type( 'digital',) so the template should be single-digital.php.
本文标签: Custom Post Type Template HierarchySingle post template
版权声明:本文标题:Custom Post Type Template Hierarchy - Single post template 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749021234a2304406.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论