From c1ca62ea2e4379225f168b6dbda98ead6c41785b Mon Sep 17 00:00:00 2001 From: Jonas Heinrich Date: Fri, 24 Jul 2020 13:32:51 +0200 Subject: [PATCH] check if search results exists --- kit/functions.php | 2 ++ kit/search.php | 31 +++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/kit/functions.php b/kit/functions.php index 7ba51a9..259cfaa 100644 --- a/kit/functions.php +++ b/kit/functions.php @@ -484,5 +484,7 @@ function search_excerpt_highlight() { $text = wp_strip_all_tags( get_the_content() ); $query = explode(' ', get_search_query()); + print_r($query); + echo generate_excerpt($text, $query, $length); } diff --git a/kit/search.php b/kit/search.php index f015a13..43f6394 100644 --- a/kit/search.php +++ b/kit/search.php @@ -44,16 +44,27 @@ get_header();

post_count); - _e("Showing results", 'kit'); - echo " "; - printf( esc_html__( '%d to %d', 'kit' ), $post_count_start, $post_count_end ); - echo " "; - _e("from total results", 'kit'); - echo " " . $wp_query->found_posts. ""; + + # Check if search results exists + if ($wp_query->found_posts) { + + $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; + $post_count_start = (($paged -1) * 10) + 1; + $post_count_end = ((($paged -1) * 10) + $wp_query->post_count); + _e("Showing results", 'kit'); + echo " "; + printf( esc_html__( '%d to %d', 'kit' ), $post_count_start, $post_count_end ); + echo " "; + _e("from total results", 'kit'); + echo " " . $wp_query->found_posts. ""; + + } else { + + echo "

"; + _e("No results found", 'kit'); + echo ".

"; + + } ?>