Archived topic
Which file/s i need to copy to make a new post template
13 replies · Started by Pete on August 24, 2015
I'm using a plugin that allows me to assign a post to a template the same as I can assign a page to a template... (i wish this was in core).
Which file/s would I need to make a copy of (then edit) to make a new single post template, just like i would a page template?
Hello Pete, you can copy the single.php and create a new single post template. You just need to rename the file to single-{post_type}.php
Maybe this could help you: https://codex.wordpress.org/Post_Type_Templates
If the plugin makes it so you can set a page template, you should actually be able to name it whatever you like.
However, if it's anything like the page template system, you'll need to put this at the top:
/**
* Template Name: My template name
*
*/
Hi guys, yep I know how to make a page template, I just need to know which file I need to copy. If I copy single.php then isn't there other files linked/included in the single.php as well that need to be customized?
content-single.php is used within single.php.
If I were you, I would copy the content-single.php code and just put it into your custom single.php file in place of the get_template_part() code.
Thanks that's exactly what I was after. Cheers.
No problem :)
Tom,
I'm trying like heck to understand the content-single.php because I would like my posts to be displayed in a certain fashion. I see that within content.php AND content-single.php there's an action called (generate-before-content and generate-after-contact). I believe it is the before action I wish to find so I can alter what is generated. I can't seem to find the source of that.
Please advise. Thank you.
content.php displays your default loop - so the blog index, archives etc..
content-single.php displays the loop on your single post pages.
Those hooks appear in both files as they're available in both loops.
You can use GP Hooks to add content into either of them.
Let me know if you need more info :)
Thanks Tom.
In looking at GP Hooks, I don't see the 'generate-after-content' hook which seems to be specific specific to the content-single file.
Jay
It's the "Generate After Content" hook in GP Hooks.
You would use PHP to make your code only apper on single posts:
<?php if ( is_single() ) : ?>
Single post code here
<?php endif; ?>
Be sure to check the "Execute PHP" checkbox.
Thanks for that, Tom.
One more follow up. Where can I permanently alter the featured image size?
For the index pages? In Customize > Blog > Post Images: https://docs.generatepress.com/article/adjusting-the-featured-images/