Advertisement:

Author Topic: How to use Google search instead of smf search  (Read 23269 times)

Offline Utech22

  • Jr. Member
  • **
  • Posts: 142
  • RealJamaicaEstate.com
    • Real Estate Forum
How to use Google search instead of smf search
« on: February 20, 2010, 01:03:57 PM »
I would like to add Google search to my website.
I am using smf2.0 core theme.

site: http://forum.fashionsjamaica.com

Offline Kill Em All

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,144
  • Gender: Male
  • Something has to go wrong. Just has to.
    • KEAGaming
Re: How to use Google search instead of smf search
« Reply #1 on: February 20, 2010, 01:15:20 PM »
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.

Offline Utech22

  • Jr. Member
  • **
  • Posts: 142
  • RealJamaicaEstate.com
    • Real Estate Forum
Re: How to use Google search instead of smf search
« Reply #2 on: February 20, 2010, 01:37:16 PM »
I want it at the top of the forum, also this one does not have a click-able search button showing.

Offline Kill Em All

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,144
  • Gender: Male
  • Something has to go wrong. Just has to.
    • KEAGaming
Re: How to use Google search instead of smf search
« Reply #3 on: February 20, 2010, 05:51:43 PM »
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.

Offline Mick.

  • Customizer
  • SMF Hero
  • *
  • Posts: 5,449
  • Gender: Male
    • idesignSMF on Facebook
    • @idesign360 on Twitter
    • idesignSMF.com
Re: How to use Google search instead of smf search
« Reply #4 on: February 20, 2010, 05:56:47 PM »
Do you mean google search like in my forum?

www.chevyavalancheclub.com

Offline Utech22

  • Jr. Member
  • **
  • Posts: 142
  • RealJamaicaEstate.com
    • Real Estate Forum
Re: How to use Google search instead of smf search
« Reply #5 on: February 20, 2010, 07:00:33 PM »

Offline Mick.

  • Customizer
  • SMF Hero
  • *
  • Posts: 5,449
  • Gender: Male
    • idesignSMF on Facebook
    • @idesign360 on Twitter
    • idesignSMF.com
Re: How to use Google search instead of smf search
« Reply #6 on: February 20, 2010, 07:03:01 PM »
Hang on....  let me write what you need to do.

Offline Mick.

  • Customizer
  • SMF Hero
  • *
  • Posts: 5,449
  • Gender: Male
    • idesignSMF on Facebook
    • @idesign360 on Twitter
    • idesignSMF.com
Re: How to use Google search instead of smf search
« Reply #7 on: February 20, 2010, 07:29:50 PM »
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:

Code: [Select]
<?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:

Code: [Select]
<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:

Code: [Select]
<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
Code: [Select]
<?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:
Code: [Select]
<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:
Code: [Select]
<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:
Code: [Select]
http://www.bluedevilcustoms.com/11.1.x%20SMF/results.phpwith 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


« Last Edit: March 30, 2011, 06:32:53 PM by bluedevil »

Offline Mick.

  • Customizer
  • SMF Hero
  • *
  • Posts: 5,449
  • Gender: Male
    • idesignSMF on Facebook
    • @idesign360 on Twitter
    • idesignSMF.com
Re: How to use Google search instead of smf search
« Reply #8 on: February 20, 2010, 07:42:47 PM »
The code for the index.template.php may look slightly different than mine.   I removed the push button since i didnt want it.

Offline kenso

  • Jr. Member
  • **
  • Posts: 115
    • Ozfarmer farming forum, Classifieds and Store
Re: How to use Google search instead of smf search
« Reply #9 on: February 25, 2010, 04:39:12 PM »
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

Offline Mick.

  • Customizer
  • SMF Hero
  • *
  • Posts: 5,449
  • Gender: Male
    • idesignSMF on Facebook
    • @idesign360 on Twitter
    • idesignSMF.com
Re: How to use Google search instead of smf search
« Reply #10 on: February 25, 2010, 05:08:21 PM »
Code: [Select]
<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
Code: [Select]
';
Make sure it has it.
« Last Edit: February 25, 2010, 05:17:01 PM by BlueDevil »

Offline Mick.

  • Customizer
  • SMF Hero
  • *
  • Posts: 5,449
  • Gender: Male
    • idesignSMF on Facebook
    • @idesign360 on Twitter
    • idesignSMF.com
Re: How to use Google search instead of smf search
« Reply #11 on: February 25, 2010, 05:11:03 PM »
This is fine.  It goes to your results.php

Code: [Select]
<?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(); ?>

Offline Mick.

  • Customizer
  • SMF Hero
  • *
  • Posts: 5,449
  • Gender: Male
    • idesignSMF on Facebook
    • @idesign360 on Twitter
    • idesignSMF.com
Re: How to use Google search instead of smf search
« Reply #12 on: February 25, 2010, 05:27:11 PM »
Kenso, what SMF series are you using?   

1.1.x?
RC2?

Offline kenso

  • Jr. Member
  • **
  • Posts: 115
    • Ozfarmer farming forum, Classifieds and Store
Re: How to use Google search instead of smf search
« Reply #13 on: February 25, 2010, 09:47:38 PM »
Hi Blue Devil, 2.0 RC2
The Farmers and self-sufficiency forum
http://www.ozfarmer.com.au

Offline Mick.

  • Customizer
  • SMF Hero
  • *
  • Posts: 5,449
  • Gender: Male
    • idesignSMF on Facebook
    • @idesign360 on Twitter
    • idesignSMF.com
Re: How to use Google search instead of smf search
« Reply #14 on: February 25, 2010, 09:57:56 PM »
Hi Blue Devil, 2.0 RC2

Ok, reply #7 should set you good.

Offline kenso

  • Jr. Member
  • **
  • Posts: 115
    • Ozfarmer farming forum, Classifieds and Store
Re: How to use Google search instead of smf search
« Reply #15 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
The Farmers and self-sufficiency forum
http://www.ozfarmer.com.au

Offline Mick.

  • Customizer
  • SMF Hero
  • *
  • Posts: 5,449
  • Gender: Male
    • idesignSMF on Facebook
    • @idesign360 on Twitter
    • idesignSMF.com
Re: How to use Google search instead of smf search
« Reply #16 on: February 25, 2010, 10:36:49 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...
Code: [Select]
<input type="text" name="q" size="21" />change the '21' to a higher a value.   Experiment with it.

Offline kenso

  • Jr. Member
  • **
  • Posts: 115
    • Ozfarmer farming forum, Classifieds and Store
Re: How to use Google search instead of smf search
« Reply #17 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
The Farmers and self-sufficiency forum
http://www.ozfarmer.com.au

Offline Mick.

  • Customizer
  • SMF Hero
  • *
  • Posts: 5,449
  • Gender: Male
    • idesignSMF on Facebook
    • @idesign360 on Twitter
    • idesignSMF.com
Re: How to use Google search instead of smf search
« Reply #18 on: February 27, 2010, 01:53:06 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.

Offline kenso

  • Jr. Member
  • **
  • Posts: 115
    • Ozfarmer farming forum, Classifieds and Store
Re: How to use Google search instead of smf search
« Reply #19 on: March 01, 2010, 09:54:46 PM »
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