nttruong
MasterCorporal
- Tham gia
- 25/02/2015
- Bài viết
- 368
- Được Like
- 614
Để thêm thanh tìm kiếm Google vào xenforo, các bạn cần vào link sau http://www.google.com.vn/cse/ để đăng ký và get code.
Sau khi điền các thông tin cần thiết bạn sẽ nhận được một bảng như sau:
Các bạn lưu ý phần Search engine unique ID nhé
Tiếp theo các bạn mở template search_results thay toàn bộ code bằng đoạn sau:
Ở đoạn trên các bạn lưu ý:
Thay đoạn 018007349847158740104:3vjyrucanzs bằng code Search engine unique ID bạn đã lấy được từ bước đăng ký.
Ảnh demo:
Chúc các bạn thành công!
Sau khi điền các thông tin cần thiết bạn sẽ nhận được một bảng như sau:
Các bạn lưu ý phần Search engine unique ID nhé
Tiếp theo các bạn mở template search_results thay toàn bộ code bằng đoạn sau:
Mã:
<xen:if is="{$search.searchConstraints.title_only}">
<xen:if is="{$search.search_query}">
<xen:title>{xen:phrase search_results_for_query}: {$search.search_query}</xen:title>
<xen:h1>{xen:phrase search_results_for_query}: <a href="{xen:link search, $search, 'searchform=1'}"><em>{$search.search_query}</em></a></xen:h1>
<xen:else />
<xen:title>{xen:phrase search_results}</xen:title>
</xen:if>
<xen:navigation>
<xen:breadcrumb href="{xen:link full:search}">{xen:phrase search}</xen:breadcrumb>
</xen:navigation>
<xen:container var="$head.robots">
<meta name="robots" content="noindex" /></xen:container>
<xen:require css="search_results.css" />
<xen:if is="{$search.searchWarnings}">
<ol class="searchWarnings">
<xen:foreach loop="$search.searchWarnings" value="$warning">
<li>{$warning}</li>
</xen:foreach>
</ol>
</xen:if>
<xen:if is="{$search.users}">
<xen:sidebar>
<div class="section userResults avatarList">
<div class="secondaryContent">
<h3>{xen:phrase matched_users}</h3>
<ul>
<xen:foreach loop="$search.users" value="$user">
<li class="userResult">
<xen:avatar user="$user" size="s" img="true" />
<xen:username user="$user" rich="true" />
<div class="userTitle">{xen:helper userTitle, $user}</div>
</li>
</xen:foreach>
</ul>
</div>
</div>
</xen:sidebar>
</xen:if>
<div class="pageNavLinkGroup">
<div class="linkGroup">
<a href="{xen:link search, $search, 'searchform=1'}">{xen:phrase search_again}</a>
</div>
<xen:pagenav link="search" linkdata="{$search}" page="{$page}" perpage="{$perPage}" total="{$totalResults}" />
</div>
<div class="section sectionMain searchResults">
<form action="" method="post">
<ol class="searchResultsList">
<xen:foreach loop="$results" value="$result" i="$i">
{xen:raw $result}
</xen:foreach>
</ol>
<xen:if is="{$userSearchMaxDate}">
<div class="secondaryContent olderMessages">
<a href="{xen:link search/member, '', 'user_id={$search.searchConstraints.user_id}', 'before={$userSearchMaxDate}'}">{xen:phrase find_older_messages}</a>
</div>
</xen:if>
<div class="sectionFooter searchResultSummary">
<span class="resultCount">{xen:phrase showing_results_x_to_y_of_z, 'start={xen:number $resultStartOffset}', 'end={xen:number $resultEndOffset}', 'total={xen:number $totalResults}'}</span>
<xen:if is="{$nextPage}"><a href="{xen:link search, $search, 'page={$nextPage}'}" class="nextLink">{xen:phrase next} ></a></xen:if>
</div>
</form>
</div>
<div class="pageNavLinkGroup">
<div class="linkGroup">
<xen:if is="{$ignoredNames}">
<a href="javascript:" class="muted jsOnly DisplayIgnoredContent Tooltip" title="{xen:phrase show_hidden_content_by_x, "names={xen:helper implode, $ignoredNames, ', '}"}">{xen:phrase show_ignored_content}</a>
</xen:if>
<a href="{xen:link search, $search, 'searchform=1'}">{xen:phrase search_again}</a>
</div>
<xen:pagenav link="search" linkdata="{$search}" page="{$page}" perpage="{$perPage}" total="{$totalResults}" />
</div>
<xen:else />
<xen:if is="{$page} > 1">
<xen:if is="{$search.search_query}">
<xen:title>{xen:phrase search_results_for_query}: {$search.search_query}</xen:title>
<xen:h1>{xen:phrase search_results_for_query}: <a href="{xen:link search, $search, 'searchform=1'}"><em>{$search.search_query}</em></a></xen:h1>
<xen:else />
<xen:title>{xen:phrase search_results}</xen:title>
</xen:if>
<xen:navigation>
<xen:breadcrumb href="{xen:link full:search}">{xen:phrase search}</xen:breadcrumb>
</xen:navigation>
<xen:container var="$head.robots">
<meta name="robots" content="noindex" /></xen:container>
<xen:require css="search_results.css" />
<xen:if is="{$search.searchWarnings}">
<ol class="searchWarnings">
<xen:foreach loop="$search.searchWarnings" value="$warning">
<li>{$warning}</li>
</xen:foreach>
</ol>
</xen:if>
<xen:if is="{$search.users}">
<xen:sidebar>
<div class="section userResults avatarList">
<div class="secondaryContent">
<h3>{xen:phrase matched_users}</h3>
<ul>
<xen:foreach loop="$search.users" value="$user">
<li class="userResult">
<xen:avatar user="$user" size="s" img="true" />
<xen:username user="$user" rich="true" />
<div class="userTitle">{xen:helper userTitle, $user}</div>
</li>
</xen:foreach>
</ul>
</div>
</div>
</xen:sidebar>
</xen:if>
<div class="pageNavLinkGroup">
<div class="linkGroup">
<a href="{xen:link search, $search, 'searchform=1'}">{xen:phrase search_again}</a>
</div>
<xen:pagenav link="search" linkdata="{$search}" page="{$page}" perpage="{$perPage}" total="{$totalResults}" />
</div>
<div class="section sectionMain searchResults">
<form action="" method="post">
<ol class="searchResultsList">
<xen:foreach loop="$results" value="$result" i="$i">
{xen:raw $result}
</xen:foreach>
</ol>
<xen:if is="{$userSearchMaxDate}">
<div class="secondaryContent olderMessages">
<a href="{xen:link search/member, '', 'user_id={$search.searchConstraints.user_id}', 'before={$userSearchMaxDate}'}">{xen:phrase find_older_messages}</a>
</div>
</xen:if>
<div class="sectionFooter searchResultSummary">
<span class="resultCount">{xen:phrase showing_results_x_to_y_of_z, 'start={xen:number $resultStartOffset}', 'end={xen:number $resultEndOffset}', 'total={xen:number $totalResults}'}</span>
<xen:if is="{$nextPage}"><a href="{xen:link search, $search, 'page={$nextPage}'}" class="nextLink">{xen:phrase next} ></a></xen:if>
</div>
</form>
</div>
<div class="pageNavLinkGroup">
<div class="linkGroup">
<xen:if is="{$ignoredNames}">
<a href="javascript:" class="muted jsOnly DisplayIgnoredContent Tooltip" title="{xen:phrase show_hidden_content_by_x, "names={xen:helper implode, $ignoredNames, ', '}"}">{xen:phrase show_ignored_content}</a>
</xen:if>
<a href="{xen:link search, $search, 'searchform=1'}">{xen:phrase search_again}</a>
</div>
<xen:pagenav link="search" linkdata="{$search}" page="{$page}" perpage="{$perPage}" total="{$totalResults}" />
</div>
<xen:else />
<xen:if is="{$search.search_query}">
<xen:title>{xen:phrase search_results_for_query}: {$search.search_query}</xen:title>
<xen:h1>{xen:phrase search_results_for_query}: <a href="{xen:link search, $search, 'searchform=1'}"><em>{$search.search_query}</em></a></xen:h1>
<xen:else />
<xen:title>{xen:phrase search_results}</xen:title>
</xen:if>
<ul class="tabs Tabs" data-panes="#damme_GoogleCustomSearch_Panes > li">
<li><a href="{xen:link search, $search}#gcs">Kết quả tìm kiếm từ Google</a></li>
<li><a href="{xen:link search, $search}#xf">Kết quả tìm kiếm từ địa phương</a></li>
</ul>
<br/>
<ul id="damme_GoogleCustomSearch_Panes">
<li id="gcs">
<div id="cse" style="padding: 10px; margin: 10px auto; border: 1px solid #a5cae4; -webkit-border-radius: 10px; -moz-border-radius: 10px; -khtml-border-radius: 10px;">Đang tải kết quả tìm kiếm từ Google ...</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1', {language : ''});
google.setOnLoadCallback(function() {
var customSearchOptions = {};
var customSearchControl = new google.search.CustomSearchControl(
'013230238191179781022:tuf0bqxwzpe',
customSearchOptions
);
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
var options = new google.search.DrawOptions();
options.enableSearchResultsOnly();
customSearchControl.draw('cse', options);
customSearchControl.execute('{$search.search_query}');
}, true);
</script>
</li>
<li id="xf">
<xen:navigation>
<xen:breadcrumb href="{xen:link full:search}">{xen:phrase search}</xen:breadcrumb>
</xen:navigation>
<xen:container var="$head.robots">
<meta name="robots" content="noindex" /></xen:container>
<xen:require css="search_results.css" />
<xen:if is="{$search.searchWarnings}">
<ol class="searchWarnings">
<xen:foreach loop="$search.searchWarnings" value="$warning">
<li>{$warning}</li>
</xen:foreach>
</ol>
</xen:if>
<xen:if is="{$search.users}">
<xen:sidebar>
<div class="section userResults avatarList">
<div class="secondaryContent">
<h3>{xen:phrase matched_users}</h3>
<ul>
<xen:foreach loop="$search.users" value="$user">
<li class="userResult">
<xen:avatar user="$user" size="s" img="true" />
<xen:username user="$user" rich="true" />
<div class="userTitle">{xen:helper userTitle, $user}</div>
</li>
</xen:foreach>
</ul>
</div>
</div>
</xen:sidebar>
</xen:if>
<div class="pageNavLinkGroup">
<div class="linkGroup">
<a href="{xen:link search, $search, 'searchform=1'}">{xen:phrase search_again}</a>
</div>
<xen:pagenav link="search" linkdata="{$search}" page="{$page}" perpage="{$perPage}" total="{$totalResults}" />
</div>
<div class="section sectionMain searchResults">
<form action="" method="post">
<ol class="searchResultsList">
<xen:foreach loop="$results" value="$result" i="$i">
{xen:raw $result}
</xen:foreach>
</ol>
<xen:if is="{$userSearchMaxDate}">
<div class="secondaryContent olderMessages">
<a href="{xen:link search/member, '', 'user_id={$search.searchConstraints.user_id}', 'before={$userSearchMaxDate}'}">{xen:phrase find_older_messages}</a>
</div>
</xen:if>
<div class="sectionFooter searchResultSummary">
<span class="resultCount">{xen:phrase showing_results_x_to_y_of_z, 'start={xen:number $resultStartOffset}', 'end={xen:number $resultEndOffset}', 'total={xen:number $totalResults}'}</span>
<xen:if is="{$nextPage}"><a href="{xen:link search, $search, 'page={$nextPage}'}" class="nextLink">{xen:phrase next} ></a></xen:if>
</div>
</form>
</div>
<div class="pageNavLinkGroup">
<div class="linkGroup">
<xen:if is="{$ignoredNames}">
<a href="javascript:" class="muted jsOnly DisplayIgnoredContent Tooltip" title="{xen:phrase show_hidden_content_by_x, "names={xen:helper implode, $ignoredNames, ', '}"}">{xen:phrase show_ignored_content}</a>
</xen:if>
<a href="{xen:link search, $search, 'searchform=1'}">{xen:phrase search_again}</a>
</div>
<xen:pagenav link="search" linkdata="{$search}" page="{$page}" perpage="{$perPage}" total="{$totalResults}" />
</div>
</li>
</ul>
</xen:if>
</xen:if>
Ở đoạn trên các bạn lưu ý:
Mã:
var customSearchControl = new google.search.CustomSearchControl(
'018007349847158740104:3vjyrucanzs',
customSearchOptions
);
Thay đoạn 018007349847158740104:3vjyrucanzs bằng code Search engine unique ID bạn đã lấy được từ bước đăng ký.
Ảnh demo:
Chúc các bạn thành công!
Sửa lần cuối bởi điều hành viên:
Bài viết liên quan
Bài viết mới