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

Tags: zblog搜索结果 zblog分页

分享到: