| Adding Google Adsense Search to your site |
Some users might have noticed that the search page on this website has been integrated with Google Adsense search. In this article I want to explain how you can hack Joomla! com_search in order to have a similar result in your website. You will need to create 2 custom files. If you don't have a directory to store custom files, create one. Personally I use a directory called custom located in the joomla site root. Create 2 files and name them g_form.php and g_results.php. The files have to begin with <?php ?>
Enter the address of your website and the width of the result area. Of course, you can refine the width later. When you're done, click on continue and you'll be presented with 2 boxes of code: The first is the search box code, the second is the search results code. Copy the code in the first box and paste it into both the g_form.php file and the g_results.php file after the php tags. Then copy the code from the second box and paste it into the g_results.php file below the code you've pasted before. The g_form.php fileWe start from the g_form.php file. 1. Remove all the <table>, <tr> and <td> opening and closing tags. 2. Then change this line: <form method="get" action="http://www.example.com" target="_top"> into: <form method="get" action="<?php echo $mosConfig_live_site; ?>/index.php" target="_top"> 3. Remove the <a> tags pointing to google.com around: <img src="http://www.google.com/logos/Logo_25wht.gif" border="0" alt="Google" align="middle"></img> and add this line rigth below: <input type="hidden" name="option" value="com_search"></input> 4. Change this line: <input type="text" name="q" size="31" maxlength="255" value="" id="sbi"></input> like this: <input type="hidden" name="q" size="20" maxlength="255" value="<?php echo $searchword; ?>" id="sbi"></input> The g_results.php fileHere there's no nedd to strip the table tags. 1. Change <?php ?> to this: <?php $channel = mosGetParam( $_REQUEST, 'channel', '' ) ; $q = mosGetParam( $_REQUEST, 'q', '' ) ; if ($q !='' && $channel !='' ) { echo "<br /><br />"; ?> 2. Close the } parentesys you opened in the previous step changing: <!-- SiteSearch Google --> <!-- Google Search Result Snippet Begins --> into this: <!-- SiteSearch Google --> <br /><br /> <?php } ?> <!-- Google Search Result Snippet Begins --> 3. Then change this line: <form method="get" action="http://www.example.com" target="_top"> into: <form method="get" action="<?php echo $mosConfig_live_site; ?>/index.php" target="_top"> 4. Remove the <a> tags pointing to google.com around: <img src="http://www.google.com/logos/Logo_25wht.gif" border="0" alt="Google" align="middle"></img> 5. Below: <td nowrap="nowrap">Add this line: <input type="hidden" name="option" value="com_search"></input> 6. Change: <input type="text" name="q" size="31" maxlength="255" value="" id="sbi"></input> into: <input type="text" name="q" size="31" maxlength="255" value="<?php echo $q; ?>" id="sbi"></input> Joomla! 1.0.xThe file to hack is search.html.php found in components/com_search/. First of all, make a backup copy of the file. 1. Around line 69 (in function searchbox ), change: </table>
</form>
<?php
}like this: </table>
</form>
<?php include_once ('custom/g_results.php'); ?>
<?php
}2. Look for: <a href="http://www.google.com/search?q=<?php echo $searchword; ?>" target="_blank"> <?php echo $image; ?></a> And change it to: <?php include_once ('custom/g_form.php'); ?> <!-- <a href="http://www.google.com/search?q=<?php echo $searchword; ?>" target="_blank"> <?php echo $image; ?></a> --> That's it for Joomla! 1.0.x. Next page will deal with Joomla! 1.5. Joomla! 1.5To be continued... Last update: 21-10-2007 10:50
|
No comment posted
| Tuesday, 16 October 2007 | |