本文章來為各位介紹一篇zblog搜索頁面美化和搜索結果分頁的教程了,這個是php版本的各位如果使用的是這個版本可以進來參考一下。
zblog php的搜索結果頁面調用的是單頁面,不能自定義,不能分頁,丑且不人性化。Search Plus插件可以優化搜索結果頁面,支持調用index模板和預留的search模板(前提是主題有),支持搜索詞高亮顯示,最重要的是列表可以自定義了。
zblog php搜索頁面美化和搜索結果分頁
插件安裝:
在應用中心搜索Search Plus直接安裝。
修改插件:
1、該插件默認只是優化了搜索界面,但是還不能分頁,搜索結果分頁還需要修改這個插件.
2、編輯zb_users/plugin/SearchPlus/下的include.php文件,找到插件的40行左右,將查詢語句變為:
- $pagebar=new Pagebar('{%host%}search.php?{q='.$q.'}&{page=%page%}',false);
- $pagebar->PageCount=$zbp->displaycount;
- $pagebar->PageNow=(int)GetVars('page','GET')==0?1:(int)GetVars('page','GET');
- $pagebar->PageBarCount=$zbp->pagebarcount;
- //Vevb.com
- $articles = $zbp->GetArticleList(
- '*',
- $w,
- array('log_PostTime' => 'DESC'), array(($pagebar->PageNow - 1) * $pagebar->PageCount, $pagebar->PageCount),
- array('pagebar' => $pagebar),
- null
- );
找到插件的70行左右修改為:
$zbp->template->SetTags('pagebar',$pagebar);
懶得找代碼的,直接把下面的代碼,覆蓋include.php文件的所有代碼:
- <?php
- require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'function' . DIRECTORY_SEPARATOR . 'searchstr.php';
- #注冊插件
- RegisterPlugin("SearchPlus","ActivePlugin_SearchPlus");
- function ActivePlugin_SearchPlus() {
- Add_Filter_Plugin('Filter_Plugin_Search_Begin','SearchPlus_Main');
- }
- function SearchPlus_Main() {
- global $zbp;
- foreach ($GLOBALS['Filter_Plugin_ViewSearch_Begin'] as $fpname => &$fpsignal) {
- $fpreturn = $fpname();
- if ($fpsignal == PLUGIN_EXITSIGNAL_RETURN) {
- $fpsignal=PLUGIN_EXITSIGNAL_NONE;return $fpreturn;
- }
- }
- if(!$zbp->CheckRights($GLOBALS['action'])){Redirect('./');}
- $q = trim(htmlspecialchars(GetVars('q','GET')));
- $qc = '<b style=/'color:red/'>' . $q . '</b>';
- $articles = array();
- $category = new Metas;
- $author = new Metas;
- $tag = new Metas;
- // $type = 'post-search';
- $zbp->title = $zbp->lang['msg']['search'] . ' "' . $q . '"';
- $template = $zbp->option['ZC_INDEX_DEFAULT_TEMPLATE'];
- if(isset($zbp->templates['search'])){
- $template = 'search';
- }
- $w=array();
- $w[]=array('=','log_Type','0');
- if($q){
- $w[]=array('search','log_Content','log_Intro','log_Title',$q);
- }else{
- Redirect('./');
- }
- if(!($zbp->CheckRights('ArticleAll')&&$zbp->CheckRights('PageAll'))){
- $w[]=array('=','log_Status',0);
- }
- $pagebar=new Pagebar('{%host%}search.php?{q='.$q.'}&{page=%page%}',false);
- $pagebar->PageCount=$zbp->displaycount;
- $pagebar->PageNow=(int)GetVars('page','GET')==0?1:(int)GetVars('page','GET');
- $pagebar->PageBarCount=$zbp->pagebarcount;
- $articles = $zbp->GetArticleList(
- '*',
- $w,
- array('log_PostTime' => 'DESC'), array(($pagebar->PageNow - 1) * $pagebar->PageCount, $pagebar->PageCount),
- array('pagebar' => $pagebar),
- null
- );
- foreach($articles as $article){
- $intro = preg_replace('/[/r/n/s]+/', '', trim(SubStrStartUTF8(TransferHTML($article->Content,'[nohtml]'),$q,170)) . '...');
- $article->Intro = str_ireplace($q,$qc,$intro);
- $article->Title = str_ireplace($q,$qc,$article->Title);
- }
- $zbp->header .= '<meta name="robots" content="noindex,follow" />' . "/r/n";
- $zbp->template->SetTags('title', $zbp->title);
- $zbp->template->SetTags('articles',$articles);
- //$zbp->template->SetTags('type',$type);
- $zbp->template->SetTags('page',1);
- $zbp->template->SetTags('pagebar',$pagebar);
- if (isset($zbp->templates['search'])) {
- $zbp->template->SetTemplate($template);
- } else {
- $zbp->template->SetTemplate('index');
- }
- foreach ($GLOBALS['Filter_Plugin_ViewList_Template'] as $fpname => &$fpsignal) {
- $fpreturn=$fpname($zbp->template);
- }
- $zbp->template->Display();
- RunTime();
- die();
- }
- function InstallPlugin_SearchPlus() {
- global $zbp;
- }
- function UninstallPlugin_SearchPlus() {
- global $zbp;
- }
- ?>
新聞熱點
疑難解答