zblog php搜索页面,Z-Blog PHP实现搜索分页

Z-BLOG PHP版本默认搜索是无法分页的,APP中心有一个Search Plus插件,此插件可以优化搜索界面,但是同样不能分页。但是我们可以修改一下这个插件。

找到插件的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);

最后附上我修改后的文件,我还修改了其他的一些小bug,直接替换原插件的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 = '' . $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('/[\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 .= '' . "\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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值