-
jrmora
Hi, I need a little help
Subject:
Small aesthetic customization of search results page using Query Loop / Loop Template and a Layout to remove sidebar. Everything went well although I didn’t manage to add some things.Here you can see:
https://jrmora.com/?s=testContext in this thread:
https://generate.support/topic/first-steps-to-create-custom-search-results-page/Now I need a help to add in the search loop with a hook Element the sentence “Showing results (X Number) for: ( searched word)” because I can’t find the correct syntax in search.php (I understand it’s called from another site).
Regards
-
Hi there,
it will require some PHP.
1. Add this PHP snippet to your site:
add_filter( 'render_block', function( $block_content, $block ) { if ( !is_admin() && is_search() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'search-title' ) !== false ) { global $wp_query; $found_posts = $wp_query->found_posts; if ( $found_posts ) { if ( $found_posts > 1 ) { $block_content = sprintf( __( 'Showing %1$s Results for: "%2$s"', 'generatepress' ), $found_posts, '<span>' . get_search_query() . '</span>' ); } elseif ( $found_posts === 1 ) { $block_content = sprintf( __( 'Showing 1 Result for: "%1$s"', 'generatepress' ), '<span>' . get_search_query() . '</span>' ); } } } return $block_content; }, 10, 2 );
2. in your Element add a Headline block with some static text for you search title and give it a CSS Class of:
search-title
-
jrmora
Hi, David.
Great! It works just as it should. Appreciate it.
Now I’m going to keep fighting with the reading time and the hit counter.
Thank you very much.
-
You’re welcome
- You must be logged in to reply to this topic.