Google Search Results Within SMF

in Tutorials on 23 Feb 2010


Get Paid: Add Google Results Within Your Forum

Demo:  Here on the header

Assuming you have access to the server...

First off...... create a file named:   results.php  (where SMF is installed).


Go to Google.com and create an account with webmasters, Webmasters Google

Once you've done that, go to settings and click on "adsense", sign-in, click on "adsense setup", then select: "adsense for search".


On that page follow thru to create the "search code".  It will ask you where do you want the results to appear.  Select "within" and
type the URL of your site with results.php at the end. i.e. yoursite.com/results.php

Once done, it will provide 2 codes.   One for the index.template.php and the other for the results.php you created.


The codes:

In your newly created page (results.php) insert:

<?php require("/home/*******/public_html/SSI.php"); 
$context['page_title_html_safe'] = 'Results';
template_header(); 
echo
'
<br />


<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>'
;

template_footer(); ?>


Remember to replace this part with the full path of your forum in the code above.  (line 1)
<?php require("/home/*******/public_html/SSI.php");  and the google code with yours.


.....and the button:

In your default theme index.template.php find:


<form id="search_form" style="margin: 0;" action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
<input type="text" name="search" value="" class="input_text" />&nbsp;
<input type="submit" name="submit" value="', $txt['search'], '" class="button_submit" />
<input type="hidden" name="advanced" value="0" />


and replace with the first code google provided you.

Should look like this:

<form action="YOUR FORUM URL/results.php" id="cse-search-box">
  <div>
<input type="hidden" name="cx" value="partner-pub-0022808160619558:cah4ko-n5ph" />
<input type="hidden" name="cof" value="FORID:10" />
<input type="hidden" name="ie" value="ISO-8859-1" />
<input type="text" name="q" size="31" />
  </div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en"></script>


Remember these are my codes.  Just replace the codes with what google provided you.

Also,.... i woundnt remove the SMF search button from the Nav bar if you have less than a 200 posts.  Meaning that chances are, not all your posts are indexed yet.   Google search results only works if threads are indexed.  If not, the page results will show zero results.




idesignSMF Team
Mick is an American theme designer for Simple Machines Forum software currently living in South Florida, USA. He runs idesignSMF.com and started tinkering with SMF in 2006 where he created several SMF forums of his own before he founded idesignSMF in 2009 to which he is dedicated full time.

idesignSMF.com | SimpleMachines.org



0 Comments


rocket_launch

Professional & Impressive. We provide top quality free SMF themes with awesome support.