- This topic has 7 replies, 4 voices, and was last updated 1 year, 11 months ago by Tom.
November 18, 2016 at 1:38 pm #245667Fatih
Hi, I’m trying to create a template for a custom post type. I have created the file single-posttype.php. and I have noticed that it also uses the content.php. How can I create content-posttype.php and make single-posttype.php use it? I know this sounds complicated but I hope I made it clear.
ThanksNovember 18, 2016 at 8:20 pm #245759TomLead DeveloperLead Developer
In your file, find:
<?php get_template_part( 'content', 'single' ); ?>
Now if your file is named content-posttype.php, replace it with:
<?php get_template_part( 'content', 'posttype' ); ?>November 19, 2016 at 1:24 am #245790Fatih
Awesome, thank you so much 🙂November 19, 2016 at 2:12 pm #245891TomLead DeveloperLead DeveloperOctober 18, 2017 at 2:34 am #405422Alberto
This information is very useful, thanks!
I’m also working with custom post types and I want to edit not only the page template but also the archive page. So in my child theme I’ve created single-myCPT.php where I wrote
<?php get_template_part( 'content', 'single-myCPT' ); ?>
I’ve also created archive-myCPT.php but I don’t know how to reference my custom content replacing get_post_format().
<?php get_template_part( 'content', get_post_format() ); ?>
Hope I explained well…
Thanks in advance!October 18, 2017 at 4:24 pm #405890TomLead DeveloperLead Developer
get_template_part( 'content', 'single-myCPT' )
Will look for a file like this:
If you’re already using a custom single-myCPT.php file, you might as well copy the code inside content-single.php, and replace this with it:
get_template_part( 'content', 'single' )
get_template_part()is cool as it allows you to only change the loop – not the entire single.php file. In your case, it’s probably easier to keep everything in one file.February 12, 2019 at 11:20 pm #808941s2prod
If i want to create a custom page, which page of your theme will be most usefull to get a basis ?
content.php, page.php ??February 13, 2019 at 8:34 am #809486
- You must be logged in to reply to this topic.