Site logo

[Resolved] Custom Post Template

Home Forums Support [Resolved] Custom Post Template

Home Forums Support Custom Post Template

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #862225
    Robbert

    Hi, this is probably a question that’s been asked before, but from the support topics I read I still didn’t understand it fully.

    I’m trying to create a custom post layout so I can add some custom fields that will be the same on all those posts.

    I thought I could simply copy single.php and put in the child theme folder as single-posttemplate.php and then I could select it in the post editor under Page Attributes. However, it doesn’t show up. Or does this only apply to pages?

    Some clarification would be appreciated. Thanks!

    #862351
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Did you add the /* Template Name: part to the top of the file?: https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-custom-page-templates-for-global-use

    Let me know 🙂

    #862480
    Robbert

    Hi Tom, I did add that indeed, and I do see the option to select the template when I make a new page. However, I think I misunderstood something, so please correct me if I’m wrong:

    If I want to make a template for posts, I need to make a new custom post type first, and then single-customposttypename.php will be used for that? Meaning you can only have one template per custom post type, not multiple templates you can select in a dropdown menu like you can with pages.

    Am I understanding it correctly?

    Best, Rob

    #863022
    Tom
    Lead Developer
    Lead Developer

    If it’s just a template used for posts, you don’t need to create a custom post type.

    You’d just need to do something like this in the file header:

    /*
     * Template Name: Featured Article
     * Template Post Type: post, page, product
     */
    #863529
    Robbert

    Thanks, Tom, it works. Don’t know what I did wrong earlier.

    #864173
    Tom
    Lead Developer
    Lead Developer

    Glad I could help! 🙂

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