We’ll show you how to add a simple function to your search page that displays the search keyword and the number of results in this tutorial. This functionality was requested by an email from one of our users. Make a proposal if you’d like us to cover a particular topic.
1
|
<h2 class = "pagetitle" >Search Result for <?php /* Search Count */ $allsearch = new WP_Query( "s=$s&showposts=-1" ); $key = wp_specialchars( $s , 1); $count = $allsearch ->post_count; _e( '' ); _e( '<span class="search-terms">' ); echo $key ; _e( '</span>' ); _e( ' — ' ); echo $count . ' ' ; _e( 'articles' ); wp_reset_query(); ?></h2> |
The following is an example of what the code above will produce:
15 articles found when searching for twitter.
1
2
3
4
|
.search-terms { background-color :yellow; color : blue ; } |