- This topic has 13 replies, 7 voices, and was last updated 3 years, 1 month ago by Tom.
-
AuthorPosts
-
September 3, 2020 at 12:37 pm #1429816Espen
Hi,
I’m curious about the new generate_do_template_part in GP 3.0. I’m looking to redesign my current website and move it over to GP, so I am testing out GP. So far I’m really liking the focus on clean and fast code!
Some questions:
In the GP 3.0 Alpha launch post it says “Imagine building your custom templates as Block Elements and dynamically displaying them in place of the standard theme loop across your site.”
I may be way off here, and please correct me if I am but:
1. Does this mean that we will be able to for instance design custom category pages with the block editor? And have control of the layout of the loop itself on those pages?
2. If so, will it work with the visibility controls in GPP so that I can for instance have different category loop layouts for different categories?
3. Won’t this require a sort of display posts block, to replace the loop with?
4. What about dynamically pulling in metadata such as the current category etc?
4. It looks as if the generate_do_template_part in GP 3.0 opens up a lot of possibilities, but to really use them I guess we will need a new version of GPP? Is that correct, and if so when can we expect it? π
Great job on GP 3.0. I’ll continue to test it out and let you know if I discover anything buggy π
Best Regards,
Espen
September 3, 2020 at 2:02 pm #1429909TomLead DeveloperLead DeveloperHi there,
Great questions!
1. That’s correct. This action will allow us to build post loop templates in Block Elements, and then hook them into the theme.
2. Full control with Display Rules – different designs for different archives etc..
3. Not necessarily. We’re introducing Template Tags (like in the current Header Element) into Block Elements in GPP 1.12.0. This will allow you to dynamically pull in data from the current post object while using the Headline Block in GenerateBlocks. Post titles, post meta etc..
4. See above.
5. Yes, if you’re wanting a full UI to build with. You can, of course, use code:
// Disable the core template part on the blog page. add_filter( 'generate_do_template_part', function( $do ) { if ( is_home() ) { return false; } return $do; } ); // Add our own. add_action( 'generate_before_do_template_part', function() { if ( is_home() ) : ?> <article <?php post_class(); ?>> <div class="inside-article"> <h1><?php the_title(); ?></h1> <a class="button" href="<?php the_permalink(); ?>">Read more!</a> </div> </article> <?php endif; } );
It’s basically a way to replace the theme loop without using child theme files.
Hope this helps! Thanks for testing 3.0 π
September 3, 2020 at 2:27 pm #1429947EspenThat sounds fantastic, Tom!
I’m very excited to start playing with all the new functionality π
-Espen
September 4, 2020 at 9:45 am #1430989TomLead DeveloperLead DeveloperDefinitely a lot of cool things that can be done now! π
September 16, 2020 at 2:54 am #1445373CraigHi,
I have recently upgraded to GP premium 1.12.0-alpha.1 and I’m not able to see any option for generate_do_template_part or generate_menu_bar_items in the elements hook options. Am I possibly missing something or am I just to premature to test these features?
Testing GP 3.0 and aside from my confusion above, so far so good. Thanks!
September 16, 2020 at 3:16 am #1445397DavidStaffCustomer SupportHi there,
generate_menu_bar_items is a standard action hook – it will be added to the Elements list in the next update. In the meantime you can manually add it by selecting the Custom Hook.
generate_do_template_part is more complicated then that and will be something that GPP will integrate in a future update. In the meantime the code method Tom provided is the way to go.
September 16, 2020 at 3:42 am #1445424CraigThat’s great! Thanks David. Really pleased with what you guys have come up with for 3.0
Keep up the good work!
September 16, 2020 at 4:08 am #1445455DavidStaffCustomer SupportGlad to be of help – and thanks for the great feedback.
September 22, 2020 at 12:42 pm #1454386SamuelJust to make sure I fully understand what’s available with generate_do_template_part currently.
It sounds like using Elements linked to generate_do_template_part you can use the block editor to replace the loop for specific content.
We need a new GPP to be able to use a block element with dynamic content (i.e. a block layout where you can replace title, excerpt, post, categories, etc with data at run time).
Is there any way in PHP code to tell GP to display a block element or are we limited to using the Elements UI to select where an element shows?
September 23, 2020 at 9:53 am #1455740TomLead DeveloperLead DeveloperYou could definitely use code to insert a Block Element into that hook. The issue right now is making it so the Block Element works nicely within the loop. There are some issues there we need to figure out before it will work perfectly.
October 10, 2020 at 9:02 am #1482206Heinrichi cannot find the documentation for the generate_do_template hook. is there a guide available?
October 10, 2020 at 4:50 pm #1482640TomLead DeveloperLead DeveloperHi there,
We’re working on a documentation article with some examples.
For now, the post above explains the main concept: https://generatepress.com/forums/topic/question-about-gp-3-0-and-generate_do_template_part/#post-1429909
Let me know if you are trying to do some specific and I’ll do my best to help π
February 12, 2021 at 2:23 pm #1656377acelaHere’s another example of the power of this new capability in GP 3.0, which David assisted with…
It easily swaps out the (poor) default WordPress search function for a much better Google custom search engine:
With just those few lines of code, your search capability is seamlessly upgraded sitewide. Wow.
February 13, 2021 at 11:28 am #1657166TomLead DeveloperLead DeveloperThanks for sharing! That’s awesome π
-
AuthorPosts
- You must be logged in to reply to this topic.