In your WordPress theme folder, find the search.php file. Simply add the following where you’d like to display the number of search results. You’ll also notice the snippet also includes some additional verbage to sweeten the output, which you are free to edit of course. Also note that this code is optimized for WordPress v2.9 and above.
<h2 class="pagetitle">
Search Results for
<?php /* Search Count */
$allsearch = &new WP_Query("s=$s&showposts=-1");
$key = esc_html($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>
Double hat tip to WPRecipes and ProBlogDesign.
This entry was written by , posted on May 11, 2010 at 2:13 pm, filed under Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.