Site logo

[Resolved] Search result should have same template as custom blog page with query loop

Home Forums Support [Resolved] Search result should have same template as custom blog page with query loop

Home Forums Support Search result should have same template as custom blog page with query loop

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #2542489
    Dimitri

    Hello,
    i could easily create a custom blog archive page with query loop (great experience, thank you for this!)
    Now, the search result page obviously has default archive layout, which is different.
    How can i “magically” display it on the same way as my custom blog archive page with query loop?

    thank you

    #2542910
    David
    Staff
    Customer Support

    Hi there,

    when you add a Query Loop to a Loop Template, DO NOT set any Query Parameters, just check the “Inherit Query from Template”.
    Then that Elements Display Rules can be set to All Archives and/or Search Results for example. And the one loop element will work for all of them.

    #2542967
    Dimitri

    Dear David,
    i did as you suggested.
    Unfortunately, blog page shows now almost nothing and search page shows the layout according to the customizer settings.
    Do i still missing something?

    #2542978
    David
    Staff
    Customer Support

    Can you make sure that the Query Loop has no Parameters set ? And then activate the “Inherit Query from Template”.

    Display rules
    Location 1 – > Blog
    Location 2 – > Search Results

    let me know

    #2543664
    Dimitri

    Dear David,
    I am a little confused.
    I do not see even the possibility to set Query Loop Parameters when i “activate Inherit Query from Template” – they are disapearing.

    And what about display rules you mentioned?
    I afraid, i need some more explanations…

    #2543919
    Dimitri

    Dear David,
    maybe you meant, i should create a Block Element “Loop Template”, so that will be default template and to use it everywhere i need with “Inherit Query from Template” ?

    I deed it and it works! But it shows all posts 🙁

    So my new questions are:
    – by archives: how can i show only posts from current category?
    – by search results: how can i show only relevant post

    thank you for our paticence

    #2543952
    David
    Staff
    Customer Support

    maybe you meant, i should create a Block Element “Loop Template”, so that will be default template and to use it everywhere i need with “Inherit Query from Template” ?

    That is correct.

    You must NOT add any Params to the Query Loop block, just activate Inherit Query from Template

    As a suggestion i would do:

    1. for Display Rules: All Archives as this will be used on all taxonomies etc.
    2. a separate Element Loop Template for the Search archives, as you may need to add other content before the loop on this page.

    #2543997
    Dimitri

    Thank you David, it works!
    Now i am struggling with missing Archive Title and Search Page Title like “Your results for [keyword]”.
    Your hint appreciated.

    #2544236
    David
    Staff
    Customer Support

    OK,

    so for the Archive Title, add a Headline Block, and in the Blocks Toolbar, use the GP Dynamic Data option to set the Title.

    https://docs.generatepress.com/article/dynamic-data/

    We will be adding this to a GB update soon.

    For the Search Terms, you will need to register a shortcode using this PHP Snippet:

    add_shortcode('search_term', function(){
        return get_search_query();
    });

    Then you can use a Headline Block and include the [search_term] shortcode inside

    #2544249
    Dimitri

    Top, wonderfull, thanks a lot!

    #2545093
    David
    Staff
    Customer Support

    Glad to be of help!

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