Site logo

Archived topic

[GP 3.0] Custom page template – how to?

9 replies · Started by AdB on October 7, 2020

Viewing posts 1–10 of 10

Hi, I've a question related to the 3.0 version of Generate Press.

Like I already asked here https://generatepress.com/forums/topic/custom-page-template-how-to/ for the previous version, now I'd like to know how can I create a custom page template for the 3.0 (always because I'll use Advanced Custom Fields and a Child Theme - not using Blocks)

I couldn't find anything (yet?) in the documentation, only these:
https://generatepress.com/generatepress-3-0-a-new-era/ ---> generate_do_template_part()

and

https://generatepress.com/forums/topic/generate_do_template_part-does-not-call-the-content/#post-1450158
https://generatepress.com/forums/topic/question-about-gp-3-0-and-generate_do_template_part/#post-1429909

but still it's pretty unclear.

Also, should I do something about the custom page templates (of a child theme) created with the old version of Generate Press or should they stay like they are? (I already updated my test-site, and everything is working fine..)

thank you!
Davide

Hi there,

There's no issue with keeping your child theme get_template_part() as it is right now.

You will want to do a quick comparison to make sure the other parts of the template files match with the new version, but the actual get_template_part() can stay as is.

ok thanks.
and how can I create a new custom page template with GP3.0?

I've to make a copy of the page.php file, renamed it. After that, how can I "link" the template with the contents (---> content-page.php)?

Should I use generate_do_template_part in the (copy of) page.php file?
thanks
D.

What are you wanting to customize in this template, exactly? Which part of the default template are you wanting to alter/replace?

Hi Tom,
maybe I didn't express myself good enough :D

I'm using advanced custom fields, so I need a specific template for some pages in order to output there the contents (repetition fields, flexible contents, etc.).
So, to replace the entire content of a page with the contents of the advanced custom fields.

The original question is:
How can I create a custom page template in GP 3.0?
Back then, you'll need to make a copy of the page.php, rename it (let's say in kontakt.php), then make a copy of the content-page.php file, rename it (content-kontakt.php) and then "link them" together by changing this in the kontakt.php page

while ( have_posts() ) : the_post();
  get_template_part( 'content', 'kontakt' );

With the version 3.0, the page.php file has this instead

if ( generate_has_default_loop() ) {
     while ( have_posts() ) :

	the_post();

	generate_do_template_part( 'page' );

     endwhile;
		}

Does it make sense to change the function "generate_do_template_part( 'page' );" with "get_template_part( 'content', 'kontakt' );" in order to create a custom page template?
If not, how can I use the function "generate_do_template_part() to achieve what I'd like to achieve?

Thank you!
D.

Yes, if you need to create custom template files, you can replace generate_do_template_part( 'page' ); with your own get_template_part( 'content', 'kontakt' ); function.

Depending on what you're doing to these files, it may not be necessary to create custom template files, but if you do need to, the above is the method to use.

Hi Tom - are you planning on putting together any documentation on how to use generate_do_template_part in child themes? I've literally just got my head around how to use get-template-part with ACF (similar to the OP) to make custom designs, only to find that GP is no longer using it! 😂😂😂

If possible, it would be great to understand how to use generate_do_template_part in similar situations.

Also - I understand you're saying get-template-part will still work in the child theme, but is there any likelihood of conflicts with the parent theme in the future?

Thanks so much!

Yes, I'll be writing some docs on it.

generate_do_template_part() is just a wrapper for get_template_part() - the benefit is that we can now turn off/replace get_template_part() using conditions without having to create child themes.

There's nothing extra to learn or do if you're already using child themes with get_template_part() - it all works exactly as it did before.

This new method will simply give us more flexibility without needing custom template files :)

Great - thanks for confirming that Tom!
Caroline

No problem! :)

This archived topic is closed to new replies.