There are several guides on the web covering the addition of Google based search to FlatPress sites.

This plugin takes a slightly different approach by extending the existing SearchBox plugin to also support Google searches and hence the possibility of generating income (if you are lucky) via Google AdSense.

First download the GoogleSearchBox plugin and copy into your fp-plugins folder.

Now go to Google and sign in to you Google account. Select the Custom Search product and generate a search engine for your site. For the look and feel of your custom search engine choose Iframe and then get the code.

When generating the code for you custom Google search engine it is necessary to provide the url for the static page on your FlatPress site where search results will be displayed, for example http://www.gsys.biz/GoogleSearchResults.

On your FlatPress site generate a static page for the Google search results to be displayed on giving it the same name you used previously, e.g. GoogleSearchResults. Into this page paste the search results code provided by Google, for example:

<p>
<div id="cse-search-results"></div>
<script type="text/javascript">
  var googleSearchIframeName = "cse-search-results";
  var googleSearchFormName = "cse-search-box";
  var googleSearchFrameWidth = 400;
  var googleSearchDomain = "www.google.com";
  var googleSearchPath = "/cse";
</script>
<script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
</p>

Now go the Plugins page of you FlatPress site. First disable SearchBox. Then enable GoogleSearchBox and go to the configuration page for GoogleSearchBox.

Decide on how you want the search box to be displayed. In its concise form a text box and search button are displayed. The full search box allows the user to decide what form of search to perform - titles only, full or via Google.

In the Target field place the name of your static page where Google search results will appear, e.g. GoogleSearchResults.

In cx enter the unique Id of your search engine. This can be found in the Search box code provided by Google.

The cof field controls where adverts are displayed by Google in the search results. As you change the position you want advertising to be placed in the Google control panel this value will change in the Search box code window. Currently the values appear to be

  • FORID:9 to display adverts to the right
  • FORID:10 to display adverts on the top and to the right
  • FORID:11 to display adverts and the top and bottom

The ie field is the encoding for your Google search results and again can be found in the Search box code generated by Google.

Finally, go the the Widgets control panel on you FlatPress site and place the GoogleSearchBox widget into the appropriate bar.

Note, if a visitor has javascript disabled then they will not be able to issue a search against Google. Instead the search will revert back to using the built in facilities provided by FlatPress.

August 21, 2010

Add a comment

Comments

  • Thank you for the plugin. I use it in my blog.

    But a question. If i use the option "web", there are no results. Also here on your page. Any idea what to do?

    Greetings from germany.
    Written on December 22, 2010 by Detlef
  • Hi Detlef,

    Thank you for the comment. It just goes to prove the Java idiom of test, test and test again. An error in the JavaScript allowed the code to work on IE, but fail in FireFox. An updated version of the plug-in is now available from the download link in the original article.
    Written on December 22, 2010 by Ross
  • Thank you.

    I see, it's ok here in your blog. Unfortunately it does not work in my blog. Tested with FF 3.6.13 and IE 8.

    (I installed the plugin again and deleted the content cache and the index.)
    Written on December 22, 2010 by Detlef
  • I get this in the source of the searchpage:

    var googleSearchIframeName = “cse-search-results”;
    var googleSearchFormName = “cse-search-box”;
    var googleSearchFrameWidth = 400;
    var googleSearchDomain = “www.google.com”;
    var googleSearchPath = “/cse”;


    On your page it is

    var googleSearchIframeName = "cse-search-results";
    var googleSearchFormName = "cse-search-box";
    var googleSearchFrameWidth = 400;
    var googleSearchDomain = "www.google.com";
    var googleSearchPath = "/cse";


    There is something wrog with the quotation marks. But all documents are utf-8 coded.
    Written on December 22, 2010 by Detlef
  • Please delete my last comment. The charakters i wrote are displayed differently. What i mean is, that in the source of my search-result-page are no quotation marks, but things like this &#038;_#_8220 (Please think away the underscores).
    Written on December 23, 2010 by Detlef
  • I found the problem. The plugin works properly if inline HTML in the BBCode-Plugin is disabled.

    Hope this helps
    Written on December 23, 2010 by Detlef
  • Hmm... probably not the final answer as it appear to work with inline HTML in both states at this end, but glad to hear it is working for you!

    Time for some more digging...
    Written on December 23, 2010 by Ross
  • Detlef,

    Going back to your earlier comment, could I enquire what language your browser was set to when editing the static page which displays the Google search results?

    If it was set to German I wonder if that is what caused the quotes within the javascript to be replaced by &#038;_#_8220; and &#038;_#_8221; ?

    If you can edit the static file so that it actually contains quotes does this make a difference?

    One other thing I have noticed with playing around is that the [html] and [/html] tags are required. I take it these are still present?
    Written on December 23, 2010 by Ross
  • I've found that just at that moment. It all works after I've entered the html-tags. I thought I have tried that yesterday. But maybe I was too tired and have therefore overlooked something. I did not know that this is needed on static pages, even if the inline-option is enabled.

    To answer your question, the browser is set to UTF-8.

    Thanks again for your kind help. I hope you did not spend too much time with my problems.
    Written on December 23, 2010 by Detlef
  • As a small thank you, I'm going to create a German language file. But that probably after Christmas. I have looked at that. It seems to be not so hard. I'll send it to you, if it is done..
    Written on December 23, 2010 by Detlef
  • That's great news Detlef - glad the plugin is now working for you!
    Written on December 24, 2010 by Ross
  • A big thanks to Detlef for providing a German translation for this plugin. Version 1.2 incorporating support for the German language is now available from http://www.gsys.biz/blog/2010/08/17/googlesearchbox-1-2.zip
    Written on December 29, 2010 by Ross
  • This seems to rely on PrettyURLs--I'm a little confused about what I'm supposed to put in as my page title. When I created the static page, I called it "SearchResults"; as a title I entered "Search". If I go to that page, its url is http://www.mysite.com/?page=SearchResults . So in the plugin settings under "Target", do I enter ?page=SearchResults or just SearchResults? I'm not getting results with either--I just get the normal Flatpress search results instead.
    Written on February 22, 2011 by Jeff
  • Hi Jeff,

    The "Target" should be set to the name of the static page you created for your google search results, in your case "SearchResults".

    To verify the name of your google search results page go to your static admin page at http://www.mysite.com/admin.php?p=static. The value to enter in "Target" will be found in the "Page" column.

    I'm not sure you have the static page set up correctly at the moment. The url you gave of http://www.mysite.com/?page=SearchResults looks like a dynamic page, it should look like http://www.mysite.com/SearchResults/
    Written on February 23, 2011 by Ross