最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
zblog搜索页面美化和搜索结果分页的教程
时间:2022-06-25 16:16:29 编辑:袖梨 来源:一聚教程网
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;
$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文件的所有代码:
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 = '' . $q . '';
$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('/[rns]+/', '', 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 .= '' . "rn";
$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;
}
相关文章
- 人们熟悉的寄居蟹属于以下哪种分类 神奇海洋11月21日答案 11-21
- 第五人格11.22共研服有什么更新 11月22日共研服更新内容介绍 11-21
- 原神恰斯卡怎么培养 11-21
- 无期迷途四星装束是谁 11-21
- 王者荣耀帝丹高中校服怎么获得 11-21
- 光遇姆明季后续版本怎么玩 11-21