Bước 1 : Vào đây đăng kí ID web/forum của bạn và lấy mã ID của google. Bước 2 : Tạo một file tên là google.php với nội dung sau :
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'test');
define('CSRF_PROTECTION', true);
// change this depending on your filename
// ################### PRE-CACHE TEMPLATES AND DATA ######################// get special phrase groups // get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array('GOOGLE', );
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');
// #######################################################################// ######################## START MAIN SCRIPT ############################ // ######################## START MAIN SCRIPT ############################ // #######################################################################
$navbits = construct_navbits(array('' => 'Google Site Search'));
$navbar = render_navbar_template($navbits);
// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle = 'Google Custom Search';
// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######
$templater = vB_Template::create('GOOGLE');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
print_output($templater->render());
?>
Sau đó upload lên host ngang hàng với admincp , index.php , ...
– Style : Chọn Skin cần chèn
– Chủ đề : viết tên Google
– Template : Chèn đoạn code sau :
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
<head>
<title>{vb:raw vboptions.bbtitle}</title> {vb:raw headinclude} </head> <body> {vb:raw header} {vb:raw navbar}
<div id="pagetitle">
<h1>{vb:raw pagetitle}</h1> </div>
<h2 class="blockhead">Google Custom Search</h2> <div class="blockbody">
<div class="blockrow"> <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";
</script>
<script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script> </div> </div> {vb:raw footer} </body> </html>
Nhấn Save and Reload .
Vào AdminCP >> Styles & Templates >> Style Manager >> Chọn skin cần chỉnh , Edit templates >> Navigation / Breadcrumb Templates »Navbar , tìm code sau :
<form action="search.php?do=process" method="post" id="navbar_search" class="navbar_search"> <input type="hidden" name="s" value="{vb:raw session.sessionurl}" />
<input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" /> <input type="hidden" name="do" value="process" />
<span class="textboxcontainer"><span><input type="text" value="" name="query"
class="textbox" tabindex="99"/></span></span>
<span class="buttoncontainer"><span><input type="image" class="searchbutton"
src="{vb:stylevar imgdir_button}/search.png" name="submit"
onclick="document.getElementById('navbar_search').submit;" tabindex="100"/></span></span> </form>
Thay thế bằng code sau :
<form action="http://đường dẫn forum của bạn" id="cse-search-box">
<input type="hidden" name="cx" value="Id của bạn đã đăng kí ở bước 1, dạng : Chữ số : Chữ cái
" />
<input type="hidden" name="cof" value="FORID:9" />
<input type="hidden" name="ie" value="UTF-8" />
<span class="textboxcontainer"><span><input type="text" value="" name="q" class="textbox" /></span></span>
<span class="buttoncontainer"><span><input type="image" class="searchbutton" src="{vb:stylevar imgdir_button}/search.png" name="sa"
onclick="document.getElementById('navbar_search').submit;" /> </span></span>
</form>
<script type="text/javascript" src="http://www.google.com./cse/brand?form=cse-search- box&lang=en"></script>
Nhấn Save and Reload .
Chú ý : Nếu bạn lỗi phông chữ , bạn có thể thay UTF-8 thành ISO-8859-1