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
« Prev Post Next Post »
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)
E. Fudd on Rabbits as food: I'm so deepwy sowwy if...
Wendy on Rabbits as food: I shared the second paragraph...
Rus on Recycled toilet paper: This is a marketing issue. ...
Rus on Computer security avoidance: I'm Confused.  I thought IT...
Rich on Computer security avoidance: An observation: Where I work...
Dave on Computer security avoidance: Rich, I can't engage the...
Wendy on Computer security avoidance: Can't you passive-aggressively walk over...
Rich on Computer security avoidance: And this is exactly the...
Deano on Display .mov thumbnails in WinXP: Brilliant, had trouble installing in...
Dave on Computer security avoidance: I wonder that every day. ...