Template files for post types other that Posts and Pages.
-
I wanted to create a specific template file for a custom post type (e.g. no date, no author info and definitely no posts’ categories).
So, I have registered a custom non-hierarchical post type and called it “song” which can have tags of its own (I called them “song-type”) and belong to categories of its own (I called them “release”).
When I add a “song”, say that it belongs to such and such “release” and tag it with something; it’s still shown as a post in the “Uncategorized” post category.
I searched a bit and found that adding ‘page-attributes’ to the array of what the custom type suppots gives Page functionalities to custom post types…so, I edited my function to look like this.
function post_type_songs() { register_post_type( 'song', array( 'music' => __('song'), 'public' => true, 'show_ui' => true, 'supports' => array( 'post-thumbnails', 'page-attributes', 'excerpts', 'custom-fields',) ) ); register_taxonomy( 'releases', 'song', array( 'hierarchical' => true, 'music' => __('releases') ) ); register_taxonomy( 'songtype', 'song', array( 'hierarchical' => false, 'music' => __('SongType'), 'query_var' => 'songtype', 'rewrite' => array('slug' => 'songtype' ) ) ); } add_action('init', 'post_type_songs');
So, I added this to the already existing list of what my custom post type supports (omitted the whole thing here) and Page functionalities were now visible on the edit screen; which included templates as well. I created a new template without date, author information, yet with keys for some custm fields. Yet, when I press save, the template goes back to default even though I set it to the one named Song output.
Am I trying to do something that isn’t possible yet?
P.S. This is what I was using for reference:
https://wpengineer.com/impressions-of-custom-post-type/P.P.S. One more thing makes me see it’s not acting page-like: it has the unnecessary /blog/ in its URI, which pages do not have.
- The topic ‘Template files for post types other that Posts and Pages.’ is closed to new replies.