- This topic has 13 replies, 2 voices, and was last updated 3 years, 5 months ago by
Fernando.
-
AuthorPosts
-
November 2, 2022 at 12:04 pm #2398883
Ian
Using the new Loop Content and Query Loop to style archives, search and blog. How do we display the regular Archive Title + Description when using the Query Loop to create archive templates?
November 2, 2022 at 2:44 pm #2399041Ian
I think I see these 2 WordPress blocks that will work for Archives.
Archive Title
Term DescriptionHow do we automate titles for Search results? Something similar to the default search results title?
November 2, 2022 at 5:38 pm #2399147Fernando Customer Support
Hi Ian,
To clarify first, are these inquiries in reference to using the Block Element – Loop Template?
If so,
1. To get the Title, create a GB Headline Block, and enable the dynamic data in the tool bar settings of the Block. Then, set the dynamic text type to title. Example: https://share.getcloudapp.com/P8u742ep
2. To get the Description, you can use a Dynamic Content Block. Set the type to term description. Reference: https://docs.generatepress.com/article/dynamic-blocks/#dynamic-content
3. Create a Headline Block. Enable dynamic data as done in step one. Add
my-search-titleto the class list of the Headline Block. Lastly, add this PHP snippet:add_filter( 'generate_dynamic_element_text', function( $text, $block ) { if ( !is_admin() && is_search() && ! empty( $block['attrs']['className'] ) && 'my-search-title' === $block['attrs']['className'] ) { $text = 'Search Results: ' . get_search_query(); } return $text; }, 10, 2 );Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
November 2, 2022 at 5:56 pm #2399156Ian
Hi Fernando,
I think we may discussing 2 separate things. #1 and #2 are the archive titles and archive descriptions, not within the Loop Content. I was not able to use any GenerateBlocks to display these. But I was able to use the standard WordPress Archive Title, Term Description to them for archive templates. And since Blog and Search Results not have have these, there is no H1 Title section.
And thanks for the snippet. I now see a title at the top of Search Results. Now is is possible to show the default search title like:
Search Results for: search-term
November 2, 2022 at 6:22 pm #2399170Ian
Hi Fernando, I should clarify.
#1. I noticed there is a prefix that we can add so I can achieve “Search Results:” but the search term following it is not displaying the proper search term. Looks to be a title from one of the results. Having said that, usually when I build archives, I also target blog and search results. Using the GB blocks, I see Search Results in archive results. So will stick to using the default WP blocks for title and description.
#2. I can now get the dynamic content block to display term description. Thank you for this.
November 2, 2022 at 6:48 pm #2399192Fernando Customer Support
I updated the code above. Can you test that for the Search title?
November 2, 2022 at 10:09 pm #2399306Ian
Thanks for updating the snipper. I see the default Search Results: search term now. Thank you!
Is it possible to only display this headline when on the search results page and not the archive or blog page? I normally run this same template for:
Archives
Search Results
BlogIt would be handy to run one instead of having to create a second Loop Element for Search Results.
TIA Fernando! You are awesome!
November 2, 2022 at 10:27 pm #2399320Fernando Customer Support
Can you share the link to the site in question? I’ll check your structure.
You may use the Private Information field for this: https://docs.generatepress.com/article/using-the-premium-support-forum/#private-information
November 2, 2022 at 10:31 pm #2399324Ian
Hi Fernando. I did on my last reply. Let me try again in this reply. I did upload a different logo to the merged header inside Elements. Pretty sure I have done this in previous sites but never ran into this. Thx!
November 2, 2022 at 10:51 pm #2399339Fernando Customer Support
Why not just keep the GB Headline Block and remove the Archive Title Block? That should keep the Title to just one for these pages.
November 2, 2022 at 10:56 pm #2399348Ian
Thanks. Let me keep at it. I was testing it on another site to make sure I got everything to work. I will port your setup over to this staging site tomorrow. Awesome sauce and thank you!
November 2, 2022 at 11:07 pm #2399363Fernando Customer Support
You’re welcome Ian!
November 3, 2022 at 1:01 pm #2400584Ian
Hi Fernando,
Your instructions and snippet worked beautifully. It allowed me to keep targeting archives, search results and blog using the same template and still allow archive title and description to display properly as well as search results to display when needed. Excellent. Thank you!
November 3, 2022 at 5:11 pm #2400758Fernando Customer Support
You’re welcome Ian! Glad to be of assistance!
-
AuthorPosts
- You must be logged in to reply to this topic.