I would like to add Google search to my website.
I am using smf2.0 core theme.
site: http://forum.fashionsjamaica.com
http://custom.simplemachines.org/mods/index.php?mod=1930
That should get you what you need.
I want it at the top of the forum, also this one does not have a click-able search button showing.
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.
Do you mean google search like in my forum?
www.chevyavalancheclub.com
Quote from: BlueDevil on February 20, 2010, 05:56:47 PM
Do you mean google search like in my forum?
www.chevyavalancheclub.com
yes
Hang on.... let me write what you need to do.
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" />
<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&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;" />
<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&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
The code for the index.template.php may look slightly different than mine. I removed the push button since i didnt want it.
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&lang=en"></script>
Must be something simple?
Thanks in advance!
Kenso ;)
<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&lang=en"></script>
The code needs this at the end
';
Make sure it has it.
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(); ?>
Kenso, what SMF series are you using?
1.1.x?
RC2?
Hi Blue Devil, 2.0 RC2
Quote from: kenso on February 25, 2010, 09:47:38 PM
Hi Blue Devil, 2.0 RC2
Ok, reply #7 should set you good.
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
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.
Thanks again BD, I see that my g search is still not active any ideas why this is? :o
Kenso
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.
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
and how can i do for the SMF 1.1.11?
For 1.1.x users, ill write something tonight ;)
I do not understand
Quote from: ABM on June 04, 2010, 06:28:51 PM
I do not understand
It means, there is no way yet, he is writing up the code to do it now though... so you are going have to be patience.
Reply #7 updated with 1.1.x support ;)
thank you very much
Guys,
Is there anyway to make this work without adsense?
That is, just have a google search box that replaces the SMF search but does not tie into an adsense account and still shows results using the results.php file?
I applied for the Google Adsense account but it has been about 5 days and no response.
Is there a modification of your code that references the URL "www.yoursite.com" instead of an adsense account?
I already have a google search on the site but it shows the results on an external page and not inline with the forum. It also doesn't replace the default SMF search box.
Appreciate any help
I added this code to my site manually. I run version 2.0 RC3 with the default theme.
It seems to be working. It displays results inside my site from the results.php page like I wanted.
Problem...
I have my custom search account set to search within my site and not the web. Now it only displays results if the actual search word appears on my index page, no results from deeper pages. If the search word or phrase does not appear on my index page, then no results are shown.
The site is already heavily indexed at Google.
Here is the site address. http://www.home-recording-studio-forum.com (http://www.home-recording-studio-forum.com)
One question, how to make that I choose google search or smf search in to same SMF search window? Best example is search on this SMF forum.
does dis method apply to rc4? cos i want it on my forum
DanteOz please open a separate topic for your issue, this topic is marked solved and will be ignored by support staff.
Ok, thnx
Quote from: DanteOz on March 30, 2011, 05:55:15 PM
does dis method apply to rc4? cos i want it on my forum
yes.
Thnks, i did it
Bluedevil Hello, this tutorial works for SMF version 2.0 Final?
Translated by Google
Quote from: Niell on June 29, 2011, 01:51:42 PM
Bluedevil Hello, this tutorial works for SMF version 2.0 Final?
Translated by Google
Yes.
Quote from: bluedevil 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.
Please how can I remove the push button for mine, I don't need it. Thanks
Remove this bit in the code google provided you:
<input type="submit" name="sa" value="Search" />
Thank you
Got this working fine on my forum...eventually. Great work bluedevil!
Search was hurting my server's performance but this solves the problem in one swoop. Zero server resources! Better even than the fabled 'Sphinx' search mechanism that the performance experts here recommend.
It should really be made into a mod to make it more idiot proof.
I'm trying to install google adsense search on my forum. I can't find the main content line in my index.template.php file. I've attached it.
Hi,
Is this code still working for 2.0.7?
Thanks
Quote from: Mick. 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:
<?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" />
<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&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;" />
<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&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