check if search results exists

This commit is contained in:
Jonas Heinrich 2020-07-24 13:32:51 +02:00
parent 9423a7bff0
commit c1ca62ea2e
2 changed files with 23 additions and 10 deletions

View file

@ -484,5 +484,7 @@ function search_excerpt_highlight() {
$text = wp_strip_all_tags( get_the_content() ); $text = wp_strip_all_tags( get_the_content() );
$query = explode(' ', get_search_query()); $query = explode(' ', get_search_query());
print_r($query);
echo generate_excerpt($text, $query, $length); echo generate_excerpt($text, $query, $length);
} }

View file

@ -44,16 +44,27 @@ get_header();
<p> <p>
<?php <?php
global $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; # Check if search results exists
$post_count_start = (($paged -1) * 10) + 1; if ($wp_query->found_posts) {
$post_count_end = ((($paged -1) * 10) + $wp_query->post_count);
_e("Showing results", 'kit'); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
echo "<strong> "; $post_count_start = (($paged -1) * 10) + 1;
printf( esc_html__( '%d to %d', 'kit' ), $post_count_start, $post_count_end ); $post_count_end = ((($paged -1) * 10) + $wp_query->post_count);
echo "</strong> "; _e("Showing results", 'kit');
_e("from total results", 'kit'); echo "<strong> ";
echo " <strong>" . $wp_query->found_posts. "</strong>"; printf( esc_html__( '%d to %d', 'kit' ), $post_count_start, $post_count_end );
echo "</strong> ";
_e("from total results", 'kit');
echo " <strong>" . $wp_query->found_posts. "</strong>";
} else {
echo "<p>";
_e("No results found", 'kit');
echo ".</p>";
}
?> ?>
</p> </p>