当前位置:首页 > CMS教程 > 其它CMS > 列表

zblog搜索页面美化和搜索结果分页的教程

发布:smiling 来源: PHP粉丝网  添加日期:2015-12-07 15:14:55 浏览: 评论:0 

本文章来为各位介绍一篇zblog搜索页面美化和搜索结果分页的教程了,这个是php版本的各位如果使用的是这个版本可以进来参考一下。

zblog php的搜索结果页面调用的是单页面,不能自定义,不能分页,丑且不人性化。Search Plus插件可以优化搜索结果页面,支持调用index模板和预留的search模板(前提是主题有),支持搜索词高亮显示,最重要的是列表可以自定义了。

zblog php搜索页面美化和搜索结果分页

插件安装:

在应用中心搜索Search Plus直接安装。

修改插件:

1、该插件默认只是优化了搜索界面,但是还不能分页,搜索结果分页还需要修改这个插件.

2、编辑zb_users/plugin/SearchPlus/下的include.php文件,找到插件的40行左右,将查询语句变为:

  1. $pagebar=new Pagebar('{%host%}search.php?{q='.$q.'}&{page=%page%}',false); 
  2. $pagebar->PageCount=$zbp->displaycount;  
  3. $pagebar->PageNow=(int)GetVars('page','GET')==0?1:(int)GetVars('page','GET'); 
  4. $pagebar->PageBarCount=$zbp->pagebarcount; 
  5. //phpfensi.com 
  6.     $articles = $zbp->GetArticleList( 
  7.         '*',  
  8.         $w, 
  9.         array('log_PostTime' => 'DESC'), array(($pagebar->PageNow - 1) * $pagebar->PageCount, $pagebar->PageCount), 
  10.         array('pagebar' => $pagebar), 
  11.         null 
  12.     ); 

找到插件的70行左右修改为:

$zbp->template->SetTags('pagebar',$pagebar);

懒得找代码的,直接把下面的代码,覆盖include.php文件的所有代码:

  1. <?php 
  2. require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'function' . DIRECTORY_SEPARATOR . 'searchstr.php'; 
  3. #注册插件 
  4. RegisterPlugin("SearchPlus","ActivePlugin_SearchPlus"); 
  5.  
  6. function ActivePlugin_SearchPlus() { 
  7.     Add_Filter_Plugin('Filter_Plugin_Search_Begin','SearchPlus_Main'); 
  8.  
  9. } 
  10.  
  11. function SearchPlus_Main() { 
  12.     global $zbp; 
  13.  
  14.     foreach ($GLOBALS['Filter_Plugin_ViewSearch_Begin'] as $fpname => &$fpsignal) { 
  15.         $fpreturn = $fpname(); 
  16.         if ($fpsignal == PLUGIN_EXITSIGNAL_RETURN) { 
  17.             $fpsignal=PLUGIN_EXITSIGNAL_NONE;return $fpreturn; 
  18.         } 
  19.     } 
  20.  
  21.     if(!$zbp->CheckRights($GLOBALS['action'])){Redirect('./');} 
  22.  
  23.     $q = trim(htmlspecialchars(GetVars('q','GET'))); 
  24.     $qc = '<b style=\'color:red\'>' . $q . '</b>'; 
  25.  
  26.     $articles = array(); 
  27.     $category = new Metas; 
  28.     $author = new Metas; 
  29.     $tag = new Metas; 
  30.  
  31. //    $type = 'post-search'; 
  32.  
  33.     $zbp->title = $zbp->lang['msg']['search'] . ' &quot;' . $q . '&quot;'; 
  34.  
  35.     $template = $zbp->option['ZC_INDEX_DEFAULT_TEMPLATE']; 
  36.  
  37.     if(isset($zbp->templates['search'])){ 
  38.         $template = 'search'; 
  39.     } 
  40.  
  41.     $w=array(); 
  42.     $w[]=array('=','log_Type','0'); 
  43.     if($q){ 
  44.         $w[]=array('search','log_Content','log_Intro','log_Title',$q); 
  45.     }else{ 
  46.         Redirect('./'); 
  47.     } 
  48.  
  49.     if(!($zbp->CheckRights('ArticleAll')&&$zbp->CheckRights('PageAll'))){ 
  50.         $w[]=array('=','log_Status',0); 
  51.     } 
  52.  
  53. $pagebar=new Pagebar('{%host%}search.php?{q='.$q.'}&{page=%page%}',false); 
  54. $pagebar->PageCount=$zbp->displaycount;  
  55. $pagebar->PageNow=(int)GetVars('page','GET')==0?1:(int)GetVars('page','GET'); 
  56. $pagebar->PageBarCount=$zbp->pagebarcount; 
  57.  
  58.     $articles = $zbp->GetArticleList( 
  59.         '*',  
  60.         $w, 
  61.         array('log_PostTime' => 'DESC'), array(($pagebar->PageNow - 1) * $pagebar->PageCount, $pagebar->PageCount), 
  62.         array('pagebar' => $pagebar), 
  63.         null 
  64.     ); 
  65.     foreach($articles as $article){ 
  66.         $intro = preg_replace('/[\r\n\s]+/', '', trim(SubStrStartUTF8(TransferHTML($article->Content,'[nohtml]'),$q,170)) . '...'); 
  67.         $article->Intro = str_ireplace($q,$qc,$intro); 
  68.         $article->Title = str_ireplace($q,$qc,$article->Title); 
  69.     } 
  70.  
  71.     $zbp->header .= '<meta name="robots" content="noindex,follow" />' . "\r\n"; 
  72.     $zbp->template->SetTags('title', $zbp->title); 
  73.     $zbp->template->SetTags('articles',$articles); 
  74.     //$zbp->template->SetTags('type',$type); 
  75.     $zbp->template->SetTags('page',1); 
  76.     $zbp->template->SetTags('pagebar',$pagebar); 
  77.  
  78.     if (isset($zbp->templates['search'])) { 
  79.         $zbp->template->SetTemplate($template); 
  80.     } else { 
  81.         $zbp->template->SetTemplate('index'); 
  82.     } 
  83.  
  84.     foreach ($GLOBALS['Filter_Plugin_ViewList_Template'] as $fpname => &$fpsignal) { 
  85.         $fpreturn=$fpname($zbp->template); 
  86.     } 
  87.  
  88.     $zbp->template->Display(); 
  89.     RunTime(); 
  90.     die(); 
  91. } 
  92.  
  93. function InstallPlugin_SearchPlus() { 
  94.     global $zbp; 
  95.  
  96. } 
  97.  
  98. function UninstallPlugin_SearchPlus() { 
  99.     global $zbp; 
  100.  
  101. } 
  102. ?>

Tags: zblog搜索结果 zblog分页

分享到: