Show the Number of Results in WordPress search
March 18, 2009 · Print This Article
The typical WordPress search results page has the title “Search Results.” It’s not very helpful, but we can make it much more dynamic, very easily.
Let’s change our title to something like “Search Result for search terms - 8 Articles”
Open your search template file, search.php. In it, search for the following:
<h2 class="pagetitle">Search Results</h2>
Now replace this with:
<h2 class="pagetitle">
Search Results 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>
And that’s you done! You can use CSS to style individual parts of the title however you like. E.g. The HTML for the search terms will look something like this:
<span class="search-terms">search terms</span>





















Comments
Got something to say?
You must be logged in to post a comment.