- This topic has 13 replies, 3 voices, and was last updated 1 year, 10 months ago by Ying.
-
AuthorPosts
-
November 26, 2021 at 10:09 am #2024440Beatriz
Hi, I have three questions about how to display the search result:
1. In the presentation of my project category I have used one of the Content Templates and I like it very much (link 1), however in my search result the same template does not apply. I would like to create a new template for that result, so that I get a simple listing in one column and not in three, as in Projects. How can I present my search results in a single column?
2. In the title of the search result, I wanted to change it with template block, however I get my first element, and what I really want to change is the title, i.e.: “Search result for : ” see my link 2
3. In the search result I would like to customize it so that it only shows me the pages, and articles and not the directories, or categories that I would like to have private, as you can see in the link of my example. how could I solve it please ?
Thank you !
November 26, 2021 at 12:24 pm #2024741YingStaffCustomer SupportHi Beatriz,
1.This article should help for the column settings:
https://docs.generatepress.com/article/option_generate_blog_settings/2.For the search result title, you can try this PHP snippet:
function custom_search_result_title( $items) { if ( is_search() ) { $items = str_replace( "Search Results for", "Search custom Results for", $items ); } return $items; } add_filter( 'generate_search_title_output', 'custom_search_result_title', 9999, 2 );
Replace the
Search custom Results for
with your custom title.3. GP has no control of the WP search output, here’s a snippet can be used on navigation search to customize the output of the navigation search:
https://docs.generatepress.com/article/primary-navigation-layout-overview/If you only want to show the posts and pages in search result page, try this PHP snippet:
add_filter( 'generate_navigation_search_output', function() { printf( '<form method="get" class="search-form navigation-search" action="%1$s"> <input type="search" class="search-field" value="%2$s" name="s" title="%3$s" /> <input type="hidden" name="post_type" value="post" /> <input type="hidden" name="post_type" value="page" /> </form>', esc_url( home_url( '/' ) ), esc_attr( get_search_query() ), esc_attr_x( 'Search', 'label', 'generatepress' ) ); } );
Let me know if this helps ๐
Adding PHP: https://docs.generatepress.com/article/adding-php/
November 27, 2021 at 2:30 pm #2026798BeatrizThank you for your reply Ying.
1. super! it works! now I have to sort out the formatting a bit.2. I tried the code and it works but it doesn’t solve what I want to do. I don’t really want to change the title string. What I want is to present the title in a hero block. I tried it with the template content but what it shows, is the first article of my search result (as shown in my private link).
3. I tried the code but I still do not see much change, what I see in my search result, is that the contents are presented very different from each other without me finding a possible relationship. Some results only show the title, others the title plus the image and others the title, the image, the text and the read more button, independently if they are articles or pages. (see the link). I don’t understand why.
November 28, 2021 at 12:02 pm #2028074YingStaffCustomer Support1. Glad to hear that ๐
2. Search result or blog page doesn’t have its own page title, so it will automatically use the first post’s title as its title. I don’t see a way to add the dynamic title into a block element at this moment Unfortuanly. You might need to use CSS to style the default
search results for x
section.3. The reason that some of them show the excerpt some not is that some of the text nested in a container block which stops WP generate expert automatically (it’s a known Gutenberg bug). If you assign a block element – content template to the search result page, the excerpt nested in GB container might show.
For some posts that don’t have thumbnails, it’s likely they don’t have a featured image assigned in the page editor.
December 1, 2021 at 8:09 am #2033524BeatrizThank you Yin,
2- The page that lists the search results, has a title, with a phrase beginning with “RรSULTATS DE RECHERCHE POUR :” and ending with the search term. This is the title that I want to put in a header, but when I try to do it with a block, the title is taken from the first post that is found. So two H1 are generated, the title of the post and the title of the page. But it is not serious, I will create a header only with a static image.3 – I understand that some results do not show the image because there is no image. However, I have used the content template and there is still the same problem with the excerpt. I can see that some posts that belong to x category, are displayed and others are not. Or some pages that are child pages do not show the excerpt either.
December 1, 2021 at 11:42 am #2034260YingStaffCustomer SupportIn the content template, do you have a
dynamic content
block in it to show the excerpt?Let me know ๐
December 2, 2021 at 8:11 am #2035939Beatrizyes, it does, but it is present in some results and not in others.
December 2, 2021 at 11:14 am #2036240YingStaffCustomer SupportI just tested, seems even using dynamic content block in content template can’t get around the WP bug.
In that case, I would recommend using custom excerpt, or move the text out of the container block in the post.
Let me know.
December 8, 2021 at 11:14 am #2042777BeatrizHi Ying! sorry for the delay, indeed, when the text is inside a block, the excerpt does not appear.
I can solve it with the articles but not with the content of my static pages.
A simple option, for the moment, is to present only the title and the image, as a result of the search.
Thank you !December 8, 2021 at 12:32 pm #2042859YingStaffCustomer SupportYou are welcome ๐
I hope WP can get this bug fixed soon, it’s really annoying sometimes.
May 27, 2022 at 4:42 am #2235065ElvisHello Ying,
I am using a hero block element to design my search results title.
So I want to remove the default one and since element checkbox does not do that I was looking arrund the forum to see if there is a solution.I have modified the function you provided to remove the title like so:
function prefix_remove_default_search_results_title( $items ) { if ( is_search() ) { $items = str_replace( "Rezultati pretrage za: %s", "", $items ); } return; } add_filter( 'generate_search_title_output', 'prefix_remove_default_search_results_title', 9999, 2 );
It seems to be working, but I wanted to check if this seems ok to you too?
TnxMay 27, 2022 at 9:57 am #2235512YingStaffCustomer SupportHi Elvis,
There’s actually a filter to remove the search result title:
add_action( 'wp', function() { remove_action( 'generate_before_loop', 'generate_do_search_results_title' ); });
May 30, 2022 at 1:25 am #2237624ElvisSweet.
I taught there had to be something like this … just was not able to find.
Thanks Ying … awsome help.May 30, 2022 at 9:35 am #2238290YingStaffCustomer SupportYou are welcome ๐
-
AuthorPosts
- You must be logged in to reply to this topic.