Also, I wanted the search results to open within my own site. Unfortunately, to have the search results show up within my website the content area on my page needed to be at least 795 pixels wide. My webpage has 2 sidebars (one on each side of the content) with a content area that is only 400 pixels wide (which is too small for the search results to display properly).
Here’s the error that I got while trying to set up my Adsense For Search code. Notice I tried to enter 400 pixels in the “Enter Width of Results Area” section, which is what caused the error (click to enlarge).
Since the search resulsts wouldn’t display properly if I used my standard page layout, I needed to make a custom page template for displaying my search results.
The easiest way to make a new template is to copy an existing template from your theme and remove the items you don’t want. In this case I didn’t need my sidebars showing up in my search results. So my plan was to duplicate my page.php template, rename it to searchresults.php, and remove the sidebar code.
To do this I opened the page.php template in a text editor (like notepad) and saved it under a new name. Your page.php file is located within your “themes” folder on the server. I called my new template searchresults.php, but you can name yours anything you want. Next, upload your new template (which is still identical to your page.php template, but with a different name) to your themes folder (for me that’s in my “Metal Law” theme folder). Note, I’m using FireFTP to do this, but you can upload your new template using any FTP client.
Once you’ve uploaded your new PHP Theme page, navigate to it by logging into your Wordpress blog and navigating to the Theme Editor. Click the image below to expand.
Now, to make Wordpress 2.7 recognize that you’ve uploaded a new theme, you need to edit your new PHP file to include the following text at the top:
/*
Template Name: Custom Search Results
*/
?>
I’ve named my template “Custom Search Results” but you can name yours something else if you like, but you must have this text in this format pasted at the top of your new theme for this to work.
Next, you need to remove any components of the original page.php theme that you don’t want included in your new custom theme. For me that’s the sidebars. Remember, I need to remove the left and right sidebar to make room to enlarge my content section from 400 pixels to at least 795 pixels. Here’s what the template looks like before removing the sidebar code from the PHP file:
And here’s what the code for the sidebars looked like in my PHP file. To remove Sidebar1 and Sidebar2, I simply deleted the following code (click to enlarge):
and
And here’s what it looks like after removing the sidebar code from the PHP file:
Now the only thing left to do is to change my content area to more than 400 pixels wide (which is changed via the CSS style sheet).
I know that the details for my content section are shown in the “.contentLayout .content” section of my CSS style sheet. So to make changes to the size of my content area (which is currently set to 49%) I wanted to copy the details of my .content section, paste the details just below, and rename the pasted portion from “.content” to “.searchcontent” with the single change of making the width 100%.
Once I’ve pasted the new piece of div class code and changed the width to 100%, I need to change a section of my PHP file so the div class “contentLayout” refers to the new div class “searchcontent” instead of the old div class “content”. This will result in the PHP file pointing the the proper div class with a new content width of 100%.
So now instead of looking like this, with a narrow content section:
My new template looks like this, with a content section that spans the entire width of the page and takes up the space previously used by the 2 sidebars that have been removed.
The next step in the process is to create a new page for your search results. I created a new page called “Search Results”, but I had to change the Attributes settings from “Main Page (no Parent)” to a child page to prevent a “Search Results” Tab from showing up at the top of my page. Otherwise I would have a navigation tab that would confuse visitors, as shown in the picture below.
Here’s where I changed the settings from Parent to Child (I chose the “About” page as the Parent, but it really doesn’t matter what Parent page you choose).
Next, pick the new template from the dropdown list so that your new search page is using the correct template (in my case, the template is called “Custom Search Results” which is the recently created searchresults.php template with the sidebar code removed)
If by chance your new template isn’t showing up in the dropdown, check to make sure you remembered to put the code in at the top. If you remembered and the template still isn’t showing up, try switching to a different theme (like the classic theme) and then switching back to your custom theme. Sometimes WordPress doesn’t recognize the new template until you’ve reloaded your custom theme.
Once you’ve saved your new search results page, you need to tell Google the address of the page. It can be found here (right click and copy it):
Go back to your Adsense For Search setup and paste the copied address in the “Enter URL where search results will be displayed” box.
Then proceed with the final steps to get the code for your new search box. You should get two chunks of code, as shown below.
The last step is to paste the two chunks of code into your website. The first chunk of code is the code for the searchbox, so you’ll probably be pasting that into your sidebar. I used the Text/HTML widget to paste the code into my sidebar.
The next chunk of code goes in the body of your new search results page. Paste it where you’d normally be typing the content of your blog post.
Once you’ve pasted both chunks of code, save your changes and test. Here’s what my search results page looks like. Notice that the first 4 results are Google Ads, that’s fine because I’m hoping to monetize some of the search traffic (by earning $ when an ad is clicked). The rest of the search results are posts within my site that match the search query.
That’s it! You should be all set. If you have any questions please post a comment.
Popularity: 81% [?]






