[Support request] Template hierarchy

Home Forums Support [Support request] Template hierarchy

Home Forums Support Template hierarchy

  • This topic has 7 replies, 2 voices, and was last updated 5 years ago by Tom.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #824205
    tobymiguel

    The way generatepress is built it requires to make 2 template files in order to make a file for a specific post.

    For example if I have a page named “contact” I would need to create these two files:

    page-contact.php

    In page contact, I need to point it to content-page-contact.php instead of content-page.php for example.

    Am I missing something here? Is there an easier way (without taking the content from content-page.php and putting it inside page-contact.php) ?

    #824739
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    This is so people can make small changes to content-page.php without changing page.php (for example).

    If you need to make changes to both files, then it’s best to just merge the two into one custom file.

    Let me know if you need more info ๐Ÿ™‚

    #827223
    tobymiguel

    Hi Tom

    Is it possible to make a template for a single post where I do not need to change two files or merge them? But only create one new file

    #827534
    Tom
    Lead Developer
    Lead Developer

    If you need to make changes to the code within both files, you need to change them both or merge them.

    If you only need to make changes to the code in one of the files, the other one can stay untouched.

    #830417
    tobymiguel

    Hi Tom

    I only need to change the code in one of the files, content-page.php, but for a specific page. How is that possible?

    #830780
    Tom
    Lead Developer
    Lead Developer

    In that case, you would copy content-page.php and add it to your child theme. Then you can make whatever changes necessary.

    #837892
    tobymiguel

    Hi Tom

    I mean, lets say I have a page called “Contact” and I want to make a specific content-page.php for the “Contact” page only.

    I don’t see how this is possible with the template hierachy: https://wphierarchy.com/

    Since page-$slug.php leads to page.php and not content-page.php. Is there a way to target content-page.php ?

    #838231
    Tom
    Lead Developer
    Lead Developer

    .page.php itself references content-page.php here: https://github.com/tomusborne/generatepress/blob/2.2.2/page.php#L31

    You can remove the need for content-page.php by copying its contents and replacing the reference to it in page.php with them.

    If you wanted a custom template for a page, you’d need to create a Page Template: https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-custom-page-templates-for-global-use

    Let me know if that’s more clear or not ๐Ÿ™‚

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