Apr 25, 2018 Default Custom Post Type Templates We created our CPT with the parameter hasarchive set to true, which will display all testimonials in an archive page. WordPress uses a template hierarchy to display different types of content. For the custom post type, it will look for. You can use these parameters with any post type including posts, pages, attachments and custom post types. By default WordPress will query for the 'post' post type and not return pages or custom post types—if you want to do this you'll need to add more arguments or use a different argument, which I'll come to later in this tutorial. Default Custom Post Type Templates We created our CPT with the parameter hasarchive set to true, which will display all testimonials in an archive page. WordPress uses a template hierarchy to display different types of content. For the custom post type, it will look for.
Hey there, I am here for today for a quick tutorial. Recently, we have switched the Genesis Framework to the Focusblog theme by Thrivetheme.
That’s why we had to update many designs and functions. Template page attributes for custom post type is one of them.
We have two custom post types registered, “Code Snippet” and “Case Studies.” I wanted to use the existing theme template for these post types. But, Template from Page Attributes available for only ‘page’ post type.
So, here are what we did to achieve that.
Enable TEMPLATE Page Attributes for CPT on WordPress
To do this, you’ll need to open the code you wrote to register custom post type(CPT). In my case, the following is the example code I added.
[thrive_text_block color=”note”]If you look at the code, you’ll notice “‘hierarchical’ => true,“. It is one of the arguments which is false by default. We need it to make true when we added “‘page-attributes’” to supports parameter.[/thrive_text_block]
Add “‘hierarchical’ => true,” or edit if “‘hierarchical’ => false,” to “‘hierarchical’ => true,“. Add “‘page-attributes’” to the supports parameter. As sooner as you save the file after adding this, you’ll see Page Attributes in the sidebar, like the screenshot below.
Add Template Post Type to Existing Templates
Alright, now we are in the next/final part of the job. One of the fantastic enhancements was delivered in WordPress 4.7 for the template system. Using that enhancement, we can handle any template for any custom post type(CPT).
So, here is the part we are going to play around. The theme which we are using for RainaStudio has BLANK, FULL-WIDTH, LANDING, & NARROW page template. So, I open all templates one by one and add “TemplatePost Type: post, page, projects, code” after “Template Name.”
Here is the original code snippet, before adding template post type.
And the snippet after adding template post type.
As sooner as I saved the file, code had taken into action. And the image below of Template selection.
Wp Custom Post Type Template
Being a thinker without box, I am not good at writing a conclusion. So far, if the tutorial works for you, share it with your friends and WordPress community. And your comment always much appreciated.
Wp Show Posts
You will love The following tutorials: