WordPress search (2)
|
Jan 9, 2006
|
This link on the WordPress codex describes how to make the default search function return "www.example.com/search/searchterms" instead of "www.example.com/?s=searchterms". I thought it could be done with Apache mod_rewrite, but I'm not smart enough to figure that out. I tried a couple things at the mod_rewrite RewriteRule Generator, but I couldn't get anything to work. The solution from the codex works fine.
This link from the codex mentions how to show the number of search results, such as "Searching for $s returned $n results". You'd think this would be easier, but it's not. An easy way to implement it is to put it in your theme directory in a file called "search.php". Here's what part of the file should look like:
<?php if (have_posts()) :
preg_match('#FROM (.*) GROUP BY#', $request, $matches); $fromwhere = $matches[1]; $numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere"); if (0 < $numposts) $numposts = number_format($numposts); ?> Searching for <b><i><?php echo $s; ?></i></b> returned <?php echo $numposts; ?> result(s).
<?php while (have_posts()) : the_post(); ?>
Another good addition to the WordPress search function is the search hilite plugin. It hilites the search terms from search engines and the WordPress search function, and it has a style that's customizable from within the WordPress options.
Note: I haven't yet implemented any of these functions on this site. Since I'm blocked at work, I can't get much site management stuff done. I'll eventually upgrade to WordPress 2.0 and implement these search features, and this will make the world a better place. And doggonit, people like me. #technology
|
Comments:
2006-01-14 23:53:20
All changes have been made successfully (or so it seems). One note: The first improvement mentioned above can also be done with a plugin from TxFx.
2007-05-21 16:27:44
[...] seem. So I googled - and I found this support topic on wordpress.org while reading a post called WordPress Search on ddhr.org - special thanks to the author! The solution works fine with WP [...]
|