Seamless integration Google Search into Lifetype (Part 3)
Posted by coldtobi | 28 Jul, 2008, 20:54 This is the third part of the integration how-to. As an exercise, you can use the google search integrated in this blog to find the others.Just kidding, here is the list:
- Seamless integration Google Search into Lifetype (Part 1 -- Introduction)
- Register at google a Custom Search Engine (Part 2)
- Edit the template for the search results (Part 3)
- Edit the .htaccess for an additional ReWriteRule. (Part 4)
So far, you have configured yourself a CSE, and are ready to include it into Lifetype. For that, you have to modify the templates in two places: One to display the goolge search form and the other is the place where to display the results.
I tried my best to avoid messing with the PHP Code: No line of code has to be changed! However, we still need to trick lifetype. As we use the template system, we also use lifetype's engine to display the results. So lifetype actually needs to perform a search, just to present us some results we'll replace with googles one.
The problem is, that lifetype is quite smart: It won't display results, if there is no result or only one. On zero hits, it will display an error page instead, and on exaclty one hit, it will display the article found.
To get around of this, your need a search phrase for lifetype's search engine. Remember, it must return at least two pages. For example, on my blog "coldtobi" works very good. Just try some, and note down your keyword. We'll need that later.
So, lets fire up the editor. By the way. The following instructions are made to keep the down-time of the site as low as possible, by first editing temporary files and replacing the files on the server at the very last step. Though "designed to be safe", I urge you to make backups now. Don't forget your database!
So, to keep your blog intact while operating, you can make a working-copy of your template directory in the same directory where the other templates reside. For example, name it <your_template>_work.
You might want to test that: Change the template of your blog to the working copy. (Probably, you'll need go to Administration->New Template and click "Scan Templates" to make it visible). Reload your blog and if it still works, you have a working backup. Please change the template back, as we will now modify the working copy.
First, let's change the file which displays the CSE Form. For the YAML template set, this is a new file, lets call it menu_googlesearch.template.
For the other templates, please search yourself. To find out, look for that line:
(Hints: I found it in the "footer.template", like for the "Standart"-Template, or in the "header.template" for Spollo.)
<input type="hidden" name="op" value="Search" />
Whatever, remove the code for lifetype's search and paste this one: Please note, the code between "start google code" and "end_google_code" has to be replaced with your CSE Code. This one is only for reference and will not work on your blog. Insert your code from part 2 here.
<h2>Google {$locale->tr("Search")}</h2>The second file to touch is the one, which displays the search results. For YAML, again this is just another new file, for example render/ender_googlesearchresults.template. Using other template, you'd usually edit searchresults.template and replace lifetypes's code with google ones.
<div id="badges" style="float:left">
{ * start google code * }
<form action="http://blog.coldtobi.de/index.php" id="cse-search-box">
<div>
<input type="hidden" name="cx" value="partner-pub-xxxxxxxxxxxxxxxx:xxxxxxxxxxx" />
<input type="hidden" name="cof" value="FORID:10" />
<input type="hidden" name="ie" value="ISO-8859-1" />
<input type="text" name="q" size="16" />
<input type="submit" name="sa" value="Search" />
</div>
</form>
<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script>
{ * end google code * }
<br/>
</div>
Whatever you edit, make sure you use your CSE code.
<h2 class="post-title">{$locale->tr("search_results")} </h2><br/>Now all the template files have been modified. However, if you turn to the new template, you will find out, that the search won't display anything: The google search form does not trigger the required operations, so lifetype just does not know about the intention.
<div class="post-info">
{* start google code * }
<div id="cse-search-results"></div>
<script type="text/javascript">
var googleSearchIframeName = "cse-search-results";
var googleSearchFormName = "cse-search-box";
var googleSearchFrameWidth = 800;
var googleSearchDomain = "www.google.com";
var googleSearchPath = "/cse";
</script>
<script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
{* end google code *}
</div>
We'll fix that in the next part.
<—&mdash Showing ERROR? Click here!
| Comments (0) | Trackbacks (0)
Related Articles:
- Seamless integration Google Search into Lifetype (Part 3)
- Seamless integration Google Search into Lifetype (Part 2)
- Seamless integration Google Search into Lifetype (Part 1)
- Seamless integration Google Search into Lifetype (Part 4)
- La Fonera: A better way to enable RedBoot via Telnet / Ethernet (safely) [HowTo]