Add search to any blog

Cyclelicious Shop
Bicycle Lights - Wald Baskets - Dahon - Strida

IMPORTANT: This content is deprecated. Please visit the new CYCLELICIOUS 2.0.
Sunday, November 20, 2005
By Yokota Fritz

Make sure not to miss the updated information and comments below.

Walter asked for the code to add a search box to his blog. I use a tiny PHP script for universal browser compatibility, but there's a Javascript method that will work on any server.

Somewhere in your blog template, include this code to create the search box. This code is customized for Walter's blog; you just need to replace the two mentions of bikefridaywalter with the URL of your own blog.
<form id="b-search" name="b-search" action="">
<input type="text" id="b-query" name="as_q" />
<input type="hidden" name="ie" value="UTF-8" />
<input type="hidden" name="bl_url"
value="" />
<input type="submit" name="Search" id="b-searchbtn"
value="Search BikeFriday Walter"
The result of the above code will look like this:

This code is based on the code for the search box in the navbar and uses Google's Blogsearch search engine. JavaScript is usable on any server. The disadvantage is that many people disable JavaScript on their browsers. This code will work for any blog that Google Blogsearch knows about, not just blogs. Note that if you run a blog with and use the navbar, you already have a search box at the top of your blog.

You can get fancy with the interface if you want and search by author, by tag to create a primitive categorization scheme, and so forth.

Update: This code does not work with the Safari browser. Does the Blogger Navbar search box work when you surf with Safari?

Update 2: There's an easier way to do this that's free of Javascript.

    IMPORTANT: Please post comments for this article at the new CYCLELICIOUS 2.0 version of this page.
Is there any way to make this search through "archived" journal entries also? i.e. my livejournal only displays the 20 most recent entries on the page listed, therefore the search function only searches those 20 entries for the desired string.

just curious :)
can't get it to work on blogdrive. :( what's the php code?

speaking of code, here's what you need to get safari to give you a little blue rss button for your feed in the address bar:

<link rel="alternate" type="application/rss+xml" title="RSS" href="" />

obviously you'll need to replace the url with the appropriate one.
Livejournal doesn't automatically send pings when you post articles -- hence, Google Blogsearch doesn't know about your Livejournal blog.
I just sent a ping for your blog and I'll try a search in the morning (if I remember) to see what happens.

The sample code on the page is specifically for your blog so it should just work by cutting and pasting directly. PHP code requires PHP support -- is there PHP support on Blogdrive?
update: the java code worked in mozilla. i guess safari doesn't like it. oh well. all my fellow mac geeks will be without search capabilities. (and yes, i know we can use camino or explorer or whatever.. but it's so nice to not HAVE to)

i'm pleased to find that i don't have the problem that sarah does but i also find that it can't find EVERYTHING. for example, i wrote about a bunch of books including tim krabbe's "the rider" and katie alvord's "divorce your car!" a long long time ago. searches for krabbe and divorce pulled up nothing. but it also doesn't just include the stuff on the main page, either, as a search for "book" shows.

btw, php doesn't work on blogdrive as you suspected.

thanks again, r.
Here's a good technique to show a search result inside your blog, without jumping to the search engine.
short and straight forward...athnx
Hi, used the updated version, but both work great, thanks for the hack and the alternative reference!
Thanks a million for a simple, effective resolution.
Post a Comment

Links to this post:

Create a Link

Blog Widget by LinkWithin Cyclelicious Home

Scotts Valley Cycle Sport

Scotts Valley Cycle Sport Santa Cruz California


Powered by Blogger

Subscribe to
Posts [Atom]