- This topic has 9 replies, 3 voices, and was last updated 5 years, 5 months ago by
Tom.
-
AuthorPosts
-
October 7, 2020 at 12:37 pm #1477304
AdB
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-1429909but 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!
DavideOctober 7, 2020 at 2:32 pm #1477450Tom
Lead DeveloperLead DeveloperHi 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.October 7, 2020 at 3:39 pm #1477516AdB
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.October 8, 2020 at 9:19 am #1478831Tom
Lead DeveloperLead DeveloperWhat are you wanting to customize in this template, exactly? Which part of the default template are you wanting to alter/replace?
October 8, 2020 at 12:03 pm #1479073AdB
Hi Tom,
maybe I didn’t express myself good enough 😀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 pagewhile ( 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.October 9, 2020 at 8:59 am #1480668Tom
Lead DeveloperLead DeveloperYes, if you need to create custom template files, you can replace
generate_do_template_part( 'page' );with your ownget_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.
October 11, 2020 at 7:37 am #1483268Caroline
Hi Tom – are you planning on putting together any documentation on how to use
generate_do_template_partin child themes? I’ve literally just got my head around how to useget-template-partwith 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_partin similar situations.Also – I understand you’re saying
get-template-partwill still work in the child theme, but is there any likelihood of conflicts with the parent theme in the future?Thanks so much!
October 11, 2020 at 11:14 am #1483649Tom
Lead DeveloperLead DeveloperYes, I’ll be writing some docs on it.
generate_do_template_part()is just a wrapper forget_template_part()– the benefit is that we can now turn off/replaceget_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 🙂
October 11, 2020 at 12:43 pm #1483758Caroline
Great – thanks for confirming that Tom!
CarolineOctober 12, 2020 at 9:23 am #1485184Tom
Lead DeveloperLead DeveloperNo problem! 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.