返回新闻列表

pbootcms 列表页加入标题搜索功能,pboot:list添加列表直接搜索 -不用跳转到搜索页面

发布日期: 2023-07-10 | 来源: 智软设计工作室

最近制作网站的时候。因为搜索的地方比较多。比如常见问题和经销商,产品,都得搜索,用传统得{pboot:scaction}  他都会到统一得页面去,当然页可以用   <input type="hidden" name="searchtpl" value="1.html" >,置顶不同模板,但是置顶后。有些问题。比如栏目封面和当前位置,都会到搜索哪里。当然你页可以定死,但是不太灵活,万一后面又有其他栏目就又要做个模板了。下面是pboot:list列表页直接搜索得解决方法:


先找到:apps/home/controller/ParserController.php


找到:

  // 解析内容列表标签
    public function parserListLabel($content, $cscode = '')

然后:

 $count = count($matches[0]);


下面添加:

/*添加列表直接搜索 */

$keyword = request('keyword', 'vars');

/*end */

然后在

  // 扩展字段数据筛选
                    foreach ($_GET as $key => $value) {
                        if (preg_match('/^ext_[w-]+$/', $key)) { // 其他字段不加入
                            $where3[$key] = get($key, 'vars');
                        }
                    }
                }


下面添加:

// 采取keyword方式
 if ($keyword) {
    if (strpos($field, '|')) { // 匹配多字段的关键字搜索
        $field = explode('|', $field);
        foreach ($field as $value) {
            if ($value == 'title') {
                $value = 'a.title';
            }
            if ($fuzzy) {
                $like = " like '%" . $keyword . "%'"; // 前面已经转义过
            } else {
                $like = " like '" . $keyword . "'"; // 前面已经转义过
            }
            if (isset($where3[0])) {
                $where3[0] .= ' OR ' . $value . $like;
            } else {
                $where3[0] = $value . $like;
            }
        }
        if (count($field) > 1) {
            $where3[0] = '(' . $where3[0] . ')';
        }
    } else { // 匹配单一字段的关键字搜索
        if ($field) {
            if ($field == 'title') {
                $field = 'a.title';
            }
            $where3[$field] = $keyword;
        } else {
            $where3['a.title'] = $keyword;
        }
    }
}


// 数据接收
if ($_POST) {
    $receive = $_POST;
} else {
    $receive = $_GET;
}

foreach ($receive as $key => $value) {
    if (! ! $value = request($key, 'vars')) {
        if ($key == 'title') {
            $key = 'a.title';
        }
        if (preg_match('/^[w-.]+$/', $key)) { // 带有违规字符时不带入查询
            $where3[$key] = $value;
        }
    }
}

// 去除特殊键值
unset($where3['keyword']);
unset($where3['field']);
unset($where3['scode']);
unset($where3['page']);
unset($where3['from']);
unset($where3['isappinstalled']);
unset($where3['tdsourcetag']);
unset($where3['x']);
unset($where3['y']);
unset($where3['searchtpl']);
unset($where3['p']);
unset($where3['s']);

// 无任何条件不显示内容
/* 取消。不然进入没条件,列表页不显示内容,
if (! $where3) {
    $content = str_replace($matches[0][$i], '', $content);
    continue;
}
/*
end 
*/

然后还要找到:IndexController.php


在44行左右:

 if(stripos(URL,'?') !== false && stripos(URL,'/?tag=')
 //加入列表页直接搜索?keyword条件,不然会出现您访问的内容不存在,请核对后重试
 
                if(stripos(URL,'?') !== false && stripos(URL,'/?tag=') == false && stripos(URL,'/?page=') == false && stripos(URL,'/?ext_') == false && stripos(URL,'/?keyword') == false){
                    _404('您访问的内容不存在,请核对后重试!');
                }

ParserController文件在里面,pbootcms3.2.5

加入list标签直接keyword搜索,ParserController.rar


推荐技术资料

jQuery+ clipboard实现复制内容效果

2023-07-06

<!--HTML代码--><ahref="#"data-source="<ahref='{php}echo$link{/php}'>[value->title]</a>"class="copy-link-btnlayui-btnlayui-btn-xs">复制链接</a><!--引入&nbs

阅读更多

Bootstrap导航条 点击li菜单后,自动收回折叠整个菜单

2023-06-05

Bootstrap导航条 点击(单击Navbar)li菜单后,自动收回折叠整个菜单,利用jq做的。点击后再次错误,菜单按钮点击事件,<script>vara=document.querySelector(".navbar-toggler"); 

阅读更多

阿里云虚拟主机和阿里云云服务器phpmailer提示Failed to connect to server: ()解决方法

2022-12-22

阿里云虚拟主机和阿里云云服务器phpmailer无法发邮件,提示无法链接,解决办法如下:如果是虚拟主机。进入控制面板:启用PHP函数fsockopen。如果是云服务器也要启用这个函数。和网络策略里ssl端口465

阅读更多

PbootCMS后台增加自定义字段搜索解决办法

2024-12-11

主要修改 // 查找指定分类及子类文章 public function findContent($mcode, $scode, $keyword)和// 在全部栏目查找文章 public function findContentAll($mcode, $keyword) {怎么修改我截图下来了。先把扩展表字段都加入进去,然后在加入left,然后在加入要搜索的字段就可以了

阅读更多

html中解决防盗链图片问题,让图片正常加载显示的方法

2023-03-15

解决方案使用Referer Meta标签控制referer,在H5 的 header加入meta<metaname="referrer"content="never">

阅读更多

pbootcms 左侧产品栏目 高亮判断方法

2021-12-02

主要是这段代码。官方演示的不行{pboot:if('[nav:scode]'=='{sort:scode}')}left_active{/pboot:if} {pboot:nav num=6 parent=2} <li><a class="biglink {pboot:if('[nav:scode]'=='{sort:scode}'

阅读更多

pbootcms禁止国内ip访问,并后台增加ip白名单输入框,用来判断固定ip可访问,

2023-06-16

<?php/*重点代码,因为PB的模板解析执行顺序,{label:**}无法直接被php解析到,我们直接读取数据,*/$list=\core\basic\Db::table('ay_label')->field('value')->where("name='Facebook'")->find();$ip1=$list->value;$ip

阅读更多

pbootcms栏目三级分类循环与判断,更多级别也可以。

2024-04-28

大概 代码。是这样的。{pboot:nav num=10 parent=0}{pboot:if([nav:soncount]>0)}menu-item-has-children{/pboot:if} {pboot:2nav parent=[nav:scode]} {pboot:if([2nav:soncount]>0)}menu-item-has-children{/pboot:if} {pboot:3

阅读更多

html css 解决DPI=125% 网站放大网页图片的问题

2022-11-11

html css 解决DPI=125% 网站放大网页图片的问题但是我们知道这个现象的原因是因为笔记本DPI=125%导致页面整体被放大了,于是我回到浏览器中,使用Ctrl + 鼠标滚轮将网页缩小,缩小到80%的时候,我发现这个效果和UI设计稿居然保持一致了,而且图片的大小也对的上。所以到这一步,我们原因找到了,解决方案也有了,那就是通过

阅读更多