ddhr.org
WordPress search (2) Monday, Jan 9, 2006 10:15 pm

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. 

Linked:  WordPress 2.1

Dave Saturday, Jan 14, 2006 11:53 pm

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.

Pingback Monday, May 21, 2007 4:27 pm
About (more)
Hi, my name is Dave Hosier, and this website is where I write my unfounded opinions on trivial matters. Feel free to look around, but please refrain from reading anything.

contact | code | pictures | feed

Discussion (feed)
Rus on Internet echo chamber: The latter also subjects the...
Dave on Internet echo chamber: I read your comments, so...
Rus on Internet echo chamber: If he wasn't feeling so...
Rus on Where grass grows: Isn't there one house up...
Wendy on Where grass grows: Ehem...I suggested a garden in...
Rus on Favre watch: That last line is brilliant.
Dave on Where grass grows: Good point.  It wouldn't take...
Rus on Where grass grows: I feel your pain, but...
Viv on WinXP .mov thumbnails: Thank you, this worked for...
Dave on Belief and behavior: I would say he believed...