[Resolved] Which file/s i need to copy to make a new post template

Home Forums Support [Resolved] Which file/s i need to copy to make a new post template

Home Forums Support Which file/s i need to copy to make a new post template

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #131643
    Pete

    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?

    #131656
    Jean Paiva
    Developer

    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

    #131688
    Tom
    Lead Developer
    Lead Developer

    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
     *
     */
    #131703
    Pete

    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?

    #131704
    Tom
    Lead Developer
    Lead Developer

    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.

    #131706
    Pete

    Thanks that’s exactly what I was after. Cheers.

    #131711
    Tom
    Lead Developer
    Lead Developer

    No problem ๐Ÿ™‚

    #264315
    Jay

    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.

    #264434
    Tom
    Lead Developer
    Lead Developer

    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 ๐Ÿ™‚

    #264440
    Jay

    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

    #264446
    Tom
    Lead Developer
    Lead Developer

    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.

    #264505
    Jay

    Thanks for that, Tom.

    #264518
    Jay

    One more follow up. Where can I permanently alter the featured image size?

    #264617
    Tom
    Lead Developer
    Lead Developer

    For the index pages? In Customize > Blog > Post Images: https://docs.generatepress.com/article/adjusting-the-featured-images/

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.