Site logo

[Resolved] Display Archive Title & Description when Using Query Loop

Home Forums Support [Resolved] Display Archive Title & Description when Using Query Loop

Home Forums Support Display Archive Title & Description when Using Query Loop

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #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?

    #2399041
    Ian

    I think I see these 2 WordPress blocks that will work for Archives.

    Archive Title
    Term Description

    How do we automate titles for Search results? Something similar to the default search results title?

    #2399147
    Fernando
    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-title to 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

    #2399156
    Ian

    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

    #2399170
    Ian

    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.

    #2399192
    Fernando
    Customer Support

    I updated the code above. Can you test that for the Search title?

    #2399306
    Ian

    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
    Blog

    It would be handy to run one instead of having to create a second Loop Element for Search Results.

    TIA Fernando! You are awesome!

    #2399320
    Fernando
    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

    #2399324
    Ian

    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!

    #2399339
    Fernando
    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.

    #2399348
    Ian

    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!

    #2399363
    Fernando
    Customer Support

    You’re welcome Ian!

    #2400584
    Ian

    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!

    #2400758
    Fernando
    Customer Support

    You’re welcome Ian! Glad to be of assistance!

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.