In developing Petomundo!, one of the biggest drawbacks that we faced was in using the default WordPress search. At an early meeting after the Pet Breeds database was created, we would type in Beagle, and in the search results, it would be show down the list as the fourth or fifth post.
Another situation arose in dealing with all of the sub-domain content of the site. We have tons of users creating great blog posts all about the animal world, and there was no way to search the other sites using the default search. So, this needed to be addressed too.
I was a little nervous about the integration with Google Site search as I had used a variety of plugins before that didn’t work the way that I wanted to, so off I went, determined to make it work the way that I wanted.
Here are the steps in a general order.
- Start off at Google Custom Search Engine and create an account. The reason that we are using Google Custom Search Engine and not Site Search, is that site search you have to pay for, and custom search is ad supported, so it is free. Also, you can set up your adsense account and even make some change for those searches.
- Fill out all of the forms to get going. The magic comes when you get to the section about sites to search. Theoretically, you could add all of the sub sites, but Google provides a nice wild card setting by adding an asterisk the front or back end of the domain name for sub-folders, or sub-domains. I added these variables:
The first element does a comprehensive search of the whole site, sub-domains, and sub-folders. The second and third provide a refined search that will explain in a moment.
- Click on Standard (ad supported) Edition and the terms of service, and submit.
- On the next page, there is a box to try out a query, and I FYI, I have never been able to have it return anything, but it has worked for me on the site.
- Once you have completed the registration process, click on the control panel button for your site.
- The basic area can be reviewed. You may wish to have the search engine public, (there are others for code, apple stuff, etc.) When you are done there, if you would like to make money one ads, click over to the make money button in the left column.
- If you have an Adsense account, simply enter your info. One thing to keep in mind is that you need to make sure you are signed up for AdSense for Search and not just AdSense for Content or Referrals. This needs to be done to make money off the ads that will show up as part your search results.
- Once that is done, click on the code button to get the code for your site.
- For me, the goal was to host the results on my site, so I picked that option. If you are looking to make money via adsense, iFrame is the only option.
- In WordPress, create a new page called search and note the permalink for that page. For Petomundo, it is http://petomundo.com/search-2/.
- In Google, add the URL for your newly created page into the area where the search results will appear.
- Now, time to create a few pages in WordPress to handle this new content.
- Let’s start off with the page results template. Take your page.php template in your theme folder and duplicate it, renaming it searchresults.php. At the beginning of the folder add this code to distinguish it as a template page.
- Now, in the content area of your page, delete the contents of the loop and paste the code from Google into the area where the loop would have been.
- Now, for the search form, there are few options here. You may want to add it somewhere in your header, perhaps in your sidebar, or elsewhere. With Petomundo, I added it in the header, and also in the sidebar where I had another search box that people where accustomed too. I also added it to the top of the search results page so that if someone wanted to refine there search, they could do it right within the same page as the search results. Like they would with Google.
- Once the code is place, go back and edit the search page you created back in step 10 of the Google side. If you are running 2.7.* there is a box at the bottom right about page templates. Add the Search Results Page template and you should be set.
A lot of steps, but mostly copy/paste. As I mentioned up in step 2 of the Google part, there are ways to add refinements to your search. I wanted a way for people to search specifically in the Pet Breeds database, and the Petomundo Store, so I added refinements to those search items. With the Member wildcard, you can search just the member profiles for content. Looking for someone with a dog like yours? That is the method there.
Other items of note, some simple CSS will make the results look smashing on your page. I have a content box, with a white background, and then another div inside that that houses the results. That way there is some padding on the sides.
I would like to create a nice little box that houses the search box on the results page, and give it a nice header like I have done other place on the site too… But overall, I am super satisfied with the product. And unlike Google Site Search, I don’t have to pay for this, and you can have the potential to make money too.
This post was written by Jake Spurlock, a member of the BuddyPress developer community. If you’re interested in contributing to the BuddyPress blog, please log in and head to the “Write Post” link in the menu bar.