Archived topic
modify search result page
7 replies · Started by Jens on August 10, 2022
Hello,
I would like modify the search result page.
I need to change the structure of the tags.
<div class="inside-article">
<header class="entry-header" aria-label="Inhalt">
<h2 class="entry-title" itemprop="headline"><a href="/vergleich/cms-hosting/wordpress-hosting" rel="bookmark">WordPress Hosting Vergleich</a></h2>
</header>
<div class="entry-summary" itemprop="text">
<p>Text, Text, Text … </p>
</div>
<footer class="entry-meta" aria-label="Entry meta"></footer>
</div>
The search result is created in search.php about the function generate_do_template_part( 'search' );
How can I customize the search result template?
Best regards
Jens
Hi there,
the generate_do_template_part will call the relevant content template. In the absence of a specific template such as the search, it will use the content.php template.
If you want to make your own custom search content template then:
1. Copy the content.php from the parent theme, see here:
https://github.com/tomusborne/generatepress/blob/master/content.php
2. Save that copy in your Child Theme folder, and rename it to: content-search.php
3. Edit that file to meet your requirements.
Alternatively, you can use a Block Element - Content Template to build your own Search content template using GenerateBlocks:
https://docs.generatepress.com/article/block-element-content-template/
Hi David,
it's a good idea so I tried it right away.
Now I have two new questions.
I implemented in the block element a Query Loop with the setting "Inherit query from template". Now I get duplicate results and the paging (Element "Pagination") doesn't work.
Regarding duplicate results, I guess I have to deactivate the core search. Is it right? How does this works?
Is there a solution for this?
Best regards
Jens
You are NOT supposed to add the query loop block to a content template, the content template is a template for the content of each individual post.
Please do watch the video in this link to understand the concept better:
https://docs.generatepress.com/article/block-element-content-template/
Hi Ying,
now I understand the structure and could adjust the pages.
However, I still have two small problems.
I would like to have a "Details" link after the text. Not below the content.
Example:
Content, Content, Content ... -> Details
How I can convert the button to a link and wow I can add this link directly below the content.
The other question is how I can replace the pager so that is the same on all my websites. On my other sites I used the Query Loop - Pagination and the Layout and button names are completely different to the result pager.
Best regards
Jens
How did you add the excerpt? Can I have a look at your site?
If you untoggle theUse default more link or the Use theme more link option, it should remove the read more button.
If you want to add the post link, you can use a headline block or a buttons block and set its dynamiclink sourceto single post.
Hi Ying,
Thanks for your answer.
The site is not online at the moment. We plan to start in about 1 month. I think it's actually easier if I can show our site. So I would report back here as soon as the site is online.
Best regards
Jens
Yes, seeing the site codes will definitely help!
Let us know when it's online :)