$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'); ?>template hierarchy - Custom post type showing index.php|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)

template hierarchy - Custom post type showing index.php

matteradmin10PV0评论

I am creating a theme and I have created a new Custom Post Type (CPT) called 'Custom Plugins'. I am trying to get this CPT to use its own template. I have created a single-custom-plugin.php - it doesn't use that. I have created single.php (still early stages with this theme I'm building it to help me learn more) - it doesn't use that either, it uses index.php again.

I'm not sure why this isn't working - I have been referring to the WordPress Developer site for help with structuring, in particular this link and the below image.

I would share the code for the pages, but I don't feel it is relevant as both single.php and single-custom-plugin.php have been temporarily setup as empty files with a single line comment stating the filename. Here is the code for my CPT (again, super basic - maybe I did something wrong here?):

function bravo_plugin_posttype() {
    register_post_type('custom-plugins', array(
        'labels' => array(
            'name' => __('Custom Plugins'),
            'singular' => __('Custom Plugin')
        ),
        'public' => true,
        'has_archive' => true,
        'rewrite' => array(
            'slug' => 'custom-plugins'
        )
    ));
}

add_action('init', 'bravo_plugin_posttype');
Post a comment

comment list (0)

  1. No comments so far