Site logo

Archived topic

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

10 replies · Started by Dimitri on February 22, 2023

Viewing posts 1–11 of 11

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

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.

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?

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

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...

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

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.

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.

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

Top, wonderfull, thanks a lot!

Glad to be of help!

This archived topic is closed to new replies.