I wanted to find a way to display Google Adsense ads for the search results on one of my DotNetNuke driven sites. I got it to work at Celebrity Couples Online. I'm sure there is a more professional method, but here were the steps I took. This method is pretty safe.
- Create a new page on your site that is hidden (I called mine GSearch), add a text module to the page, and paste the code that Google provides for search results into that text module using the source input option. This will become your search results page. Now you just need to modify your Skin files to pass over the details in the parameter that the Google code needs to see.
- In your /admin/skins directory, create a copy of these four files.
- Search.ascx -> GoogleSearch.ascx
- Search.ascx.resx -> GoogleSearch.ascx.resx
- Search.ascx.vb -> GoogleSearch.ascx.vb
- Search.xml -> GoogleSearch.xml
- In your /admin/skins/App_LocalResources directory, create a copy of Search.ascx.resx -> GoogleSearch.ascx.resx
- You will only need to edit two of the above files.To start, open up GoogleSearch.ascx.vb
- Change Const MyFileName As String = "Search.ascx" to Const MyFileName As String = "GoogleSearch.ascx"
- Change the ExecuteSearch function to the below, inserting your own data where needed
If Not String.IsNullOrEmpty(searchText) Then
dim str as string
str = "<YOUR NEW PAGE URL>?cx=<YOUR CSE ID>%3A72pzbzmchja&cof=FORID%3A9&ie=UTF-8&q=" & Server.UrlEncode(searchText)
- Second, in GoogleSearch.ascx, change CodeFile="Search.ascx.vb" to CodeFile="GoogleSearch.ascx.vb" in top line.
- In your website skin files, change <%@ Register TagPrefix="dnn" TagName="SEARCH" Src="~/Admin/Skins/Search.ascx" %> to <%@ Register TagPrefix="dnn" TagName="SEARCH" Src="~/Admin/Skins/GoogleSearch.ascx" %>
Hoping I didn't leave out a step, but it seems to work for me. I'm not all that thrilled with Google CSE's indexing time however. I'm seeing it take upwards of two weeks to index new pages, even with me adding the pages to an XML Sitemap and requesting a re-index from the CSE tools. If you run into problems, reverting only the very last change puts the old search back. Took a little trial and error!