News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

How to use Google search instead of smf search

Started by Utech22, February 20, 2010, 01:03:57 PM

Previous topic - Next topic

Utech22

I would like to add Google search to my website.
I am using smf2.0 core theme.

site: http://forum.fashionsjamaica.com

Kill Em All



My Site: KEAGaming.com

Manual Installation of Mods
Prevent Spam and Forum Attacks
Please do not PM or email me for support unless offered, help should be publicly displayed to others.

Utech22

I want it at the top of the forum, also this one does not have a click-able search button showing.

Kill Em All

I'm sorry, but I'm not exactly sure what code you would have to replace it with then in your index.template.php. You will have to ask the mod's author that in its dedicated topic.


My Site: KEAGaming.com

Manual Installation of Mods
Prevent Spam and Forum Attacks
Please do not PM or email me for support unless offered, help should be publicly displayed to others.

Mick.

Do you mean google search like in my forum?

www.chevyavalancheclub.com

Utech22


Mick.

Hang on....  let me write what you need to do.

Mick.

#7
SMF 2.0 Only

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, http://www.google.com/webmasters/

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".
Just 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 />


<center><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>

</center></td>
        </tr>
    </tbody>
</table>'
;

template_footer(); ?>


Remember to add the full path of your forum in line 1.   I omitted it with asterisks.



.....and the custom search button:

In your default theme index.template.php find:


<div class="news normaltext">
<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 code google provided you.

Should look like this:


<div class="news normaltext">
<form action="http://www.chevyavalancheclub.com/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 wouldnt remove the SMF search button simply because you only 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.




SMF 1.1.11 and all SMF 1.1.x

Create a file called results.php in your root directory. (same directory where ssi.php is located).

Add the following to results.php
<?php

require_once(dirname(__FILE__) . '/SSI.php');

$context['page_title'] = 'Results';

obExit(true);

function 
template_main()
{
 echo 
'<center><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>

</center>'
;
}

?>



Now lets replace smf's search box for the google custom search box....

Open: Themes/default/index.template.php

Find:
<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '" style="margin: 0;">
<a href="', $scripturl, '?action=search;advanced"><img src="'.$settings['images_url'].'/filter.gif" align="middle" style="margin: 0 1ex;" alt="" /></a>
<input type="text" name="search" value="" style="width: 190px;" />&nbsp;
<input type="submit" name="submit" value="', $txt[182], '" style="width: 11ex;" />
<input type="hidden" name="advanced" value="0" />


Replace with:
<form action="http://www.bluedevilcustoms.com/11.1.x%20SMF/results.php" id="cse-search-box">
  <div>
    <input type="hidden" name="cx" value="partner-pub-0022808160619558:y2qyrg48s4v" />
    <input type="hidden" name="cof" value="FORID:10" />
    <input type="hidden" name="ie" value="ISO-8859-1" />
    <input type="text" name="q" size="31" />
    <input type="submit" name="sa" value="Search" />
  </div>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en"></script>


Replace above:
http://www.bluedevilcustoms.com/11.1.x%20SMF/results.php
with the full URL of your newly created results.php


Have fun;)

Demos:

1.1.x http://www.bluedevilcustoms.com/11.1.x%20SMF/index.php
RC3 http://www.bluedevilcustoms.com/index.php



Mick.

The code for the index.template.php may look slightly different than mine.   I removed the push button since i didnt want it.

kenso

Hi Bluedevil, having a few prob with the installation getting: Template Parse Error!
There was a problem loading the /Themes/default/index.template.php template or language file. Please check the syntax and try again - remember, single quotes (') often have to be escaped with a slash (\). To see more specific error information from PHP, try accessing the file directly.

You may want to try to refresh this page or use the default theme.
syntax error, unexpected T_STRING, expecting ',' or ';'
everything seems ok?? my results code:

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


<center><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>

</center></td>
        </tr>
    </tbody>
</table>';

template_footer(); ?>
and Index.template:


<form action="http://www.ozfarmer.com/forum/results.php" id="cse-search-box">
  <div>
    <input type="hidden" name="cx" value="partner-pub-83218928916*****:byhx8-jtoyl" />
    <input type="hidden" name="cof" value="FORID:10" />
    <input type="hidden" name="ie" value="ISO-8859-1" />
    <input type="text" name="q" size="21" />
    <input type="submit" name="sa" value="Search" />
  </div>
</form>
<script type="text/javascript" src="http://www.google.com.au/cse/brand?form=cse-search-box&amp;lang=en"></script>
Must be something simple?

Thanks in advance!
Kenso  ;)
The Farmers and self-sufficiency forum
http://www.ozfarmer.com.au

Mick.

#10
<form action="http:www.ozfarmer.com/forum/results.php" id="cse-search-box">
  <div>
    <input type="hidden" name="cx" value="partner-pub-83218928916*****:byhx8-jtoyl" />
    <input type="hidden" name="cof" value="FORID:10" />
    <input type="hidden" name="ie" value="ISO-8859-1" />
    <input type="text" name="q" size="21" />
    <input type="submit" name="sa" value="Search" />
  </div>
</form>
<script type="text/javascript" src="http:www.google.com.au/cse/brand?form=cse-search-box&amp;lang=en"></script>


The code needs this at the end
';

Make sure it has it.

Mick.

This is fine.  It goes to your results.php

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


<center><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 = "hxxp:www.google.com";
  var googleSearchPath = "/cse";
</script>
<script type="text/javascript" src="hxxp:www.google.com/afsonline/show_afs_search.js"></script>

</center></td>
        </tr>
    </tbody>
</table>'
;

template_footer(); ?>

Mick.

Kenso, what SMF series are you using?   

1.1.x?
RC2?

kenso

The Farmers and self-sufficiency forum
http://www.ozfarmer.com.au

Mick.


kenso

Hi BD, all working although it would be good to get the box hard right and there isn't anything on the results page could this be because google hasn't set it up yet? (and brilliantly done!)

Kenso
The Farmers and self-sufficiency forum
http://www.ozfarmer.com.au

Mick.

Quote from: kenso on February 25, 2010, 10:28:25 PM
Hi BD, all working although it would be good to get the box hard right and there isn't anything on the results page could this be because google hasn't set it up yet? (and brilliantly done!)

Kenso

Yea, if google hasn't indexed your threads, then this is useless.  Thats why i dont recommend removing the SMF search button off the nav bar just yet.

If you want to extend the box, if if i remember right,.... think is this...
<input type="text" name="q" size="21" />
change the '21' to a higher a value.   Experiment with it.

kenso

Thanks again BD, I see that my g search is still not active any ideas why this is? :o

Kenso
The Farmers and self-sufficiency forum
http://www.ozfarmer.com.au

Mick.

Quote from: kenso on February 27, 2010, 01:46:35 AM
Thanks again BD, I see that my g search is still not active any ideas why this is? :o

Kenso

you have a link to your site?   pm me if you dont want to post it here.

kenso

Hi BD  www.ozfarmer.com/forum it works well now, just need to work out how to move the search box over to the right.

Kenso
The Farmers and self-sufficiency forum
http://www.ozfarmer.com.au

Advertisement: