$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Custom Post Type Template Hierarchy - Single post template|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Custom Post Type Template Hierarchy - Single post template

matteradmin10PV0评论

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.

Share Improve this question asked Jan 11, 2019 at 15:33 user13286user13286 2272 gold badges13 silver badges29 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The post type name is digital (register_post_type( 'digital',) so the template should be single-digital.php.

Post a comment

comment list (0)

  1. No comments so far