Site logo

Archived topic

Template hierarchy

7 replies · Started by tobymiguel on February 28, 2019

Viewing posts 1–8 of 8

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) ?

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 :)

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

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.

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?

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

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 ?

.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 :)

This archived topic is closed to new replies.