Google AJAX Search Results in WordPress

Not even a day had passed since I figured out How to Integrate Google Custom Search Engine Results into WordPress Blog Template and I figured another way to integrate search results into WordPress.

As described at the site, “Google AJAX Search API lets you put Google Search in your web pages with JavaScript.”

One of the drawbacks to the earlier method was that the results were in an iframe, so it was less integrated in the look of the site. Another thing I wanted was to be able to switch from searching my blog to more general search.

The second method using Ajax allows for customizing css of the search results, and it has tab functionality to show different types of results.

Someone had already implemented Ajax Search in Blogger. I used the provided template to come up with a slimmed-down version of the code to put into my WordPress blog.

At first, I was going to put the search results in a separate page. But I didn’t know how to do the search form for it, so I did what the ajax blogger did and put it right on the page where the search is executed. You can view the source if you want the search code. I put the search form in a widget in the sidebar.

I wrote the code so that the “More results” link goes to my template but it’s not working for some reason. I saw in an example where it worked, though. It’s a new feature so hopefully it’s just a temporary issue. Update: It turned out it was because I didn’t include the hl parameter, which was required. Oops.

Another thing I wanted to do was take advantage of the new feature, “Linked Custom Search Engines” to show results that were not only from my blog, but from sites I link to. This would have greater focus than a general web search, and would show results from related sites when mine doesn’t have the results. However, the results aren’t what I had expected so I need to do some more research to refine the custom search engine.

Update: I won’t be dropping the other search page because it comes in handy as a template for search results. I can use the Ajax search for results on the page, but for additional results, I have to fall back on the non-Ajax search.

Update: After investing a lot of time to ensure that this worked throughout my blog, I found that there is an Ajax search plugin. I installed it to see if it would meet my needs. It’s definitely convenient to have a plugin, but it doesn’t support CSE, for example. However, for someone who doesn’t already have this functionality, the plugin is a great option.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>