- This topic has 7 replies, 4 voices, and was last updated 1 year, 11 months ago by
Tom.
-
AuthorPosts
-
November 18, 2016 at 1:38 pm #245667
Fatih
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.
Thanks
November 18, 2016 at 8:20 pm #245759Tom
Lead DeveloperLead DeveloperIn 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' ); ?>
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 19, 2016 at 1:24 am #245790Fatih
Awesome, thank you so much π
November 19, 2016 at 2:12 pm #245891Tom
Lead DeveloperLead DeveloperYou’re welcome π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentOctober 18, 2017 at 2:34 am #405422Alberto
Hello Tom!
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 #405890Tom
Lead DeveloperLead DeveloperThis line:
get_template_part( 'content', 'single-myCPT' )
Will look for a file like this:
content-single-myCPT.php
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.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentFebruary 12, 2019 at 11:20 pm #808941s2prod
Dear Tom,
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 #809486Tom
Lead DeveloperLead DeveloperIt depends on which areas you’re editing.
page.php
is likely the one you want to edit.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.