Embedding Google Search Results on blog

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
TKS
Regular
Posts: 199
Joined: Thu Nov 11, 2004 1:34 am
Location: VA, USA
Contact:

Embedding Google Search Results on blog

Post by TKS »

So, like many bloggers, I use adsense on my blog Yet Another Linux Blog.

One thing that I've done is take away my custom error pages done years ago and replaced them with static pages (using the static pages plugin). This makes things a bit more "all inclusive" feeling because everything is themed just like my blog and navigation is still intact.

On each of these static pages, I provide a google search form that will search my blog. With default behavior from google, they are directed AWAY from my blog to a results page. This isn't what I want my traffic to do...I need to keep visitors there for as long as possible so they can discover my unique content ;)

Enter google's "display search results on your page" tool in adsense. You are supposed to be able to setup a page that will display a dynamic frame of search results based upon the search form on your site.

So, I setup a static page called results.html with the static page plugin and posted the code needed to display things:

Code: Select all

<!-- Google Search Result Snippet Begins -->
<div id="googleSearchUnitIframe"></div>

<script type="text/javascript">
   var googleSearchIframeName = 'googleSearchUnitIframe';
   var googleSearchFrameWidth = 530;
   var googleSearchFrameborder = 0 ;
   var googleSearchDomain = 'www.google.com';
</script>
<script type="text/javascript"
         src="http://www.google.com/afsonline/show_afs_search.js">
</script>
<!-- Google Search Result Snippet Ends -->
I removed all markup on this static page. Now when someone hits an error page and uses a search form I display there, they should be directed to http://linux-blog.org/results.html for their search results.

When people hit the search button now, they're directed to my front page and not their search results. Not the correct behavior. Since google provides the same generic code for all websites...I think this is something s9y is doing.

The problem is, this isn't working. I have no idea why it wouldn't work. Does anyone have any idea what I'm doing wrong here?

For reference: How to Set this up on Wordpress

Google Search Form Code:

Code: Select all

<!-- SiteSearch Google -->
<form method="get" action="http://linux-blog.org/index.php?/results.html" target="_top">
<table border="0" bgcolor="#ffffff">
<tr><td nowrap="nowrap" valign="top" align="left" height="32">

</td>
<td nowrap="nowrap">
<input type="hidden" name="domains" value="linux-blog.org"></input>
<label for="sbi" style="display: none">Enter your search terms</label>
<input type="text" name="q" size="31" maxlength="255" value="" id="sbi"></input>
<label for="sbb" style="display: none">Submit search form</label>
<input type="submit" name="sa" value="Google Search" id="sbb"></input>
</td></tr>
<tr>
<td> </td>
<td nowrap="nowrap">
<table>
<tr>
<td>
<input type="radio" name="sitesearch" value="" id="ss0"></input>
<label for="ss0" title="Search the Web"><font size="-1" color="#000000">Web</font></label></td>
<td>
<input type="radio" name="sitesearch" value="linux-blog.org" checked id="ss1"></input>
<label for="ss1" title="Search linux-blog.org"><font size="-1" color="#000000">linux-blog.org</font></label></td>
</tr>
</table>
<input type="hidden" name="client" value="mynumber"></input>
<input type="hidden" name="forid" value="1"></input>
<input type="hidden" name="channel" value="mychannel"></input>
<input type="hidden" name="ie" value="ISO-8859-1"></input>
<input type="hidden" name="oe" value="ISO-8859-1"></input>
<input type="hidden" name="safe" value="active"></input>
<input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#33628C; VLC:663399;AH:center;BGC:FFFFFF;LBGC:33628C; ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF; GIMP:0000FF;FORID:11"></input>
<input type="hidden" name="hl" value="en"></input>
</td></tr></table>
</form>
<!-- SiteSearch Google -->

Any help is appreciated.

Test this out yourself:

My Search Page: http://linux-blog.org/index.php?/advsearch.html
Results should display: http://linux-blog.org/index.php?/results.html
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Embedding Google Search Results on blog

Post by garvinhicking »

Hi!

Google reflects you to

http://linux-blog.org/index.php?domains ... 3A11&hl=en

however this is not a valid static page permalink. It only can detect URLs like

http://linux-blog.org/index.php?/results.html

You might want to try to change your code so that it POSTs to:

http://linux-blog.org/index.php?serendi ... 3A11&hl=en

Note the serendipity[subpage] var, which needs to hold the static page title of your resutls.html staticpage.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
TKS
Regular
Posts: 199
Joined: Thu Nov 11, 2004 1:34 am
Location: VA, USA
Contact:

Post by TKS »

garvin,

Thanks for the prompt reply :D


It actually forms that URL itself from it's own post action...I tried this:

Code: Select all

<!-- SiteSearch Google -->
<form method="get" action="http://linux-blog.org/index.php?serendipity[subpage]=advsearch.html" target="_top">
<table border="0" bgcolor="#ffffff">
<tbody><tr><td valign="top" nowrap="nowrap" height="32" align="left">

</td>
<td nowrap="nowrap">
<input type="hidden" name="domains" value="linux-blog.org" />
<label for="sbi" style="display: none;">Enter your search terms</label>
<input type="text" name="q" size="31" maxlength="255" id="sbi" />
<label for="sbb" style="display: none;">Submit search form</label>
<input type="submit" name="sa" value="Google Search" id="sbb" />
</td></tr>
<tr>
<td> </td>
<td nowrap="nowrap">
<table>
<tbody><tr>
<td>
<input type="radio" name="sitesearch" id="ss0" />
<label for="ss0" title="Search the Web"><font size="-1" color="#000000">Web</font></label></td>
<td>
<input type="radio" name="sitesearch" value="linux-blog.org" checked="true" id="ss1" />
<label for="ss1" title="Search linux-blog.org"><font size="-1" color="#000000">linux-blog.org</font></label></td>
</tr>
</tbody></table>
<input type="hidden" name="client" value="mynumber" />
<input type="hidden" name="forid" value="1" />
<input type="hidden" name="channel" value="mychannel" />
<input type="hidden" name="ie" value="ISO-8859-1" />
<input type="hidden" name="oe" value="ISO-8859-1" />
<input type="hidden" name="safe" value="active" />
<input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#33628C;VLC:663399;AH:center;BGC:FFFFFF;LBGC:33628C;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:11" />
<input type="hidden" name="hl" value="en" />
</td></tr></tbody></table>
</form>
<!-- SiteSearch Google -->
[code]

But no dice on this.  I think the post line is for input name "cof" above...and I don't want to change that for fear of breaking everything.

So this is still a problem because the above change to [subpage] didn't work and results in the same problems as before.  Any other ideas?
TKS
Regular
Posts: 199
Joined: Thu Nov 11, 2004 1:34 am
Location: VA, USA
Contact:

Post by TKS »

Worked on this a bit more but it seems to be impossible. :( I think this may be a limitation in the static pages plugin or s9y itself :|
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

http://linux-blog.org/index.php?serendi ... earch.html

is NOT a valid pagetitle!

PAGETITLE != PERMALINK :-)

Check your static page, you set the "short URL name" (or something like that).

The name you use must lead to your staticpage, while

http://linux-blog.org/index.php?serendi ... earch.html

does not.

There is no limitation in s9y that would circumvent you to achieve what you want. :-)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
TKS
Regular
Posts: 199
Joined: Thu Nov 11, 2004 1:34 am
Location: VA, USA
Contact:

Post by TKS »

Fixed this as you pointed out with the pages NOT being permalinks.


Still no dice. Post still takes me to the front page of the blog with the same weird URL.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!
TKS wrote:Fixed this as you pointed out with the pages NOT being permalinks.
What is the pagetitle of your page?

Does it open when you call index.php?serendipity[subpage]=YOURPAGETITLE ? It must.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
TKS
Regular
Posts: 199
Joined: Thu Nov 11, 2004 1:34 am
Location: VA, USA
Contact:

Post by TKS »

garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Your search form goes to:

http://linux-blog.org/index.php?domains ... 3A11&hl=en

but it should better go to:

http://linux-blog.org/index.php?serendi ... 3A11&hl=en

Because otherwise, the google results will always go back to your mainpage. With that subpage, as I mentioned, you tell Serendipity which is the targetpage.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
TKS
Regular
Posts: 199
Joined: Thu Nov 11, 2004 1:34 am
Location: VA, USA
Contact:

Post by TKS »

No matter what, using the Static Pages I cannot get this to work at all. :(

I've been trying for many days but this just isn't going to happen. No matter what, I cannot get that URL you have above to post using the search form.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!
TKS wrote:No matter what, using the Static Pages I cannot get this to work at all. :(
You must make sure that the google <form> has a hidden GET input type that submits serendipity[subpage], did you try that?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
TKS
Regular
Posts: 199
Joined: Thu Nov 11, 2004 1:34 am
Location: VA, USA
Contact:

Post by TKS »

Yep,

Here's the code:

Code: Select all

<!-- SiteSearch Google -->
<form method="get" action="http://linux-blog.org/index.php?serendipity[subpage]=Results" target="_top">
<table border="0" bgcolor="#ffffff">
<tbody><tr><td valign="top" nowrap="nowrap" height="32" align="left">
<a href="http://www.google.com/">
<img border="0" align="middle" src="http://www.google.com/logos/Logo_25wht.gif" alt="Google" /></a>
</td>
<td nowrap="nowrap">
<input type="hidden" name="domains" value="linux-blog.org" />
<label for="sbi" style="display: none;">Enter your search terms</label>
<input type="text" name="q" size="31" maxlength="255" id="sbi" />
<label for="sbb" style="display: none;">Submit search form</label>
<input type="submit" name="sa" value="Search" id="sbb" />
</td></tr>
<tr>
<td> </td>
<td nowrap="nowrap">
<table>
<tbody><tr>
<td>
<input type="radio" name="sitesearch" id="ss0" />
<label for="ss0" title="Search the Web"><font size="-1" color="#000000">Web</font></label></td>
<td>
<input type="radio" name="sitesearch" value="linux-blog.org" checked="true" id="ss1" />
<label for="ss1" title="Search linux-blog.org"><font size="-1" color="#000000">linux-blog.org</font></label></td>
</tr>
</tbody></table>
<input type="hidden" name="client" value="mynumber" />
<input type="hidden" name="forid" value="1" />
<input type="hidden" name="channel" value="mychannel" />
<input type="hidden" name="ie" value="ISO-8859-1" />
<input type="hidden" name="oe" value="ISO-8859-1" />
<input type="hidden" name="safe" value="active" />
<input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#33628C;VLC:663399;AH:center;BGC:FFFFFF;LBGC:33628C;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:11" />
<input type="hidden" name="hl" value="en" />
</td></tr></tbody></table>
</form>
<!-- SiteSearch Google -->
Still no dice, won't work.
Last edited by TKS on Thu Apr 03, 2008 4:54 pm, edited 1 time in total.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

That's invalid code. Like I mentioned, you must add a hidden input field, like this:

Code: Select all

<form action="http://linux-blog.org/index.php" method="get">
<input type="hidden" name="serendipity[subpage]" value="Results" />
...
This leads to a URL like this:

Code: Select all

http://linux-blog.org/index.php?serendipity[subpage]=Results&domains=linux-blog.org&q=results&sa=Search&sitesearch=linux-blog.org&client=pub-3982453702542240&forid=1&channel=7810157538&ie=ISO-8859-1&oe=ISO-8859-1&safe=active&cof=GALT%3A%23008000%3BGL%3A1%3BDIV%3A%2333628C%3BVLC%3A663399%3BAH%3Acenter%3BBGC%3AFFFFFF%3BLBGC%3A33628C%3BALC%3A0000FF%3BLC%3A0000FF%3BT%3A000000%3BGFNT%3A0000FF%3BGIMP%3A0000FF%3BFORID%3A11&hl=en
Which does indeed have dice. ;)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
TKS
Regular
Posts: 199
Joined: Thu Nov 11, 2004 1:34 am
Location: VA, USA
Contact:

Post by TKS »

Garvin,

So it worked...I just had to remove the other two lines in there that would conflict with adding the two you posted above. Final version is a s follows:

Code: Select all


<!-- SiteSearch Google -->

<form action="http://linux-blog.org/index.php" method="get">
<input type="hidden" name="serendipity[subpage]" value="Results" /> 
<table border="0" bgcolor="#ffffff">
<tbody><tr><td valign="top" nowrap="nowrap" height="32" align="left">
<a href="http://www.google.com/">
<img border="0" align="middle" src="http://www.google.com/logos/Logo_25wht.gif" alt="Google" /></a>
</td>
<td nowrap="nowrap">

<label for="sbi" style="display: none;">Enter your search terms</label>
<input type="text" name="q" size="31" maxlength="255" id="sbi" />
<label for="sbb" style="display: none;">Submit search form</label>
<input type="submit" name="sa" value="Search" id="sbb" />
</td></tr>
<tr>
<td> </td>
<td nowrap="nowrap">
<table>
<tbody><tr>
<td>
<input type="radio" name="sitesearch" id="ss0" />
<label for="ss0" title="Search the Web"><font size="-1" color="#000000">Web</font></label></td>
<td>
<input type="radio" name="sitesearch" value="linux-blog.org" checked="true" id="ss1" />
<label for="ss1" title="Search linux-blog.org"><font size="-1" color="#000000">linux-blog.org</font></label></td>
</tr>
</tbody></table>
<input type="hidden" name="client" value="mynumber" />
<input type="hidden" name="forid" value="1" />
<input type="hidden" name="channel" value="mychannel" />
<input type="hidden" name="ie" value="ISO-8859-1" />
<input type="hidden" name="oe" value="ISO-8859-1" />
<input type="hidden" name="safe" value="active" />
<input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#33628C;VLC:663399;AH:center;BGC:FFFFFF;LBGC:33628C;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:11" />
<input type="hidden" name="hl" value="en" />
</td></tr></tbody></table>
</form>
<!-- SiteSearch Google -->
Thanks for your help! I'll be blogging about how to do this for Serendipity since the default google code does not work :)
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Awesome. :) Keep it up - I really like that embedded search!

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply