多条件搜索

适用范围:全站任意地方均可使用

标签作用:用于执行站内搜索功能

1、最简单的搜索示例


<form action="{pboot:scaction}" method="get">

关键字:<input type="text" name="keyword" >

<button type="submit">搜索</button>

</form>


表单提交方式为get.


使用说明:

{pboot:scaction} 为搜索提交地址

注意:表单提交方式为get,此表单默认匹配title标题字段


2、定义搜索字段示例


<form action="{pboot:scaction}" method="get">

关键字:<input type="text" name="keyword" >

<input type="hidden" name="field" value="title" >

<button type="submit">搜索</button>

</form>

或:

<form action="{pboot:scaction}" method="get">

<select name="field">

<option value="title">内容标题</option>

<option value="content">内容详情</option>

</select>

关键字:<input type="text" name="keyword" >

<button type="submit">搜索</button>

</form>




通过添加隐藏域传递field值来控制搜索的字段,也可以同时设置多个字段,如: value="title|content" ,当然这只是方式之一,后面还有!


3、定义更多搜索条件示例


<form action="{pboot:scaction}" method="get">

关键字:<input type="text" name="keyword" >

<input type="hidden" name="field" value="title" >

<input type="hidden" name="scode" value="2,3" >

<button type="submit">搜索</button>

</form>


这里只定义搜索的字段和搜索的分类。可传递的字段须在 content_query_fields() 白名单内或为 ext_* 扩展字段,非法字段会被忽略。如 author 为 admin:name="author" value="admin";也可使用非隐藏域做综合搜索。


如果需要定义的scode分类有多个,可以用逗号隔开;scode 会按栏目树展开子栏目后再搜索,不是等值匹配。同时需要注意,如果表单传递的分类和字段无效时,要考虑结果页循环是否做了限制。


(V1.3.7+)如果有多个搜索表单想定义不同的结果页模板,那么可以传递searchtpl字段来定义模板页,如:

<input type="hidden" name="searchtpl" value="test.html" >

searchtpl 必须匹配 ^[w]+.html$(仅字母数字下划线 + .html),否则回退为 search.html。


4、多条件综合搜索示例


<form action="{pboot:scaction}" method="get">

内容:<input type="text" name="content" >

标题:<input type="text" name="title" >

作者:<input type="text" name="author" >

<input type="hidden" name="scode" value="2,3" >

<button type="submit">搜索</button>

</form>


这里自定义了三个字段,同样仅限白名单字段与 ext_*。

如果URL采用兼容模式,这时候搜索应该使用POST,或者在首行添加隐藏域,<input type="hidden" name="search" >。注意:{pboot:keyword} 只读取 GET 的 keyword,在纯 POST 提交时该标签为空。

5、搜索结果列表


{pboot:search}

<a href="[search:link]">[search:title]</a>

{/pboot:search}


使用说明:

搜索结果页面使用模板search.html

num=* 每页数量,非必填,用于控制分页大小

order=* 排序方式,非必填,用于输出内容的排序方式,可选:date、sorting、istop、isrecommend、isheadline、visits、likes、oppose等字段,其中sorting为按后台填写的排序,122版本开始支持自定义模式,如:order='date desc,id desc' 、order='sorting desc,id desc',(V1.3.7+)还支持random随机排序

scode=* 分类编码,非必填,此作为第二种限制搜索分类的方式,多个分类用逗号隔开,如: scode='2,3,4';会展开栏目树含子栏目,不是等值条件

field=* 字段限制,非必填,在使用了keyword时用于限定匹配的数据库字段,多个字段用竖线隔开即可,如:field='title|content'

filter=*|x,y 数据过滤,非必填,用于对列表内容进行过滤筛选,如:filter=title|ASP,PHP 只显示标题含有ASP和PHP的内容

fuzzy=* 是否模糊匹配,非必填,可选1或0,1时为默认的模糊匹配,0则关闭


搜索结果默认执行分页,使用内容列表的分页代码即可.


6、搜索结果列表可用标签

获取当前搜索内容:{pboot:keyword}(仅读取 GET 参数 keyword)

对搜索结果关键字进行标红 mark=1 (V2.0.5新增),如:[search:title mark=1];

[search:n] 序号从0开始
[search:i] 序号从1开始
[search:id] 编号
[search:scode] 分类编码
[search:subscode] 副分类编码
[search:sortname] 分类名称
[search:subsortname] 副分类名称
[search:sortlink] 分类链接
[search:subsortlink] 副分类链接
[search:title] 标题
[search:titlecolor] 标题颜色(默认不查;须经 lfield 纳入,可用 lfield='*' 或显式列出全部所需字段,勿只写单字段)
[search:subtitle] 副标题
[search:author] 作者
[search:source] 来源(默认不查;须经 lfield 纳入,用法同上)
[search:link] 链接
[search:outlink] 外部链接
[search:date] 发布日期
[search:ico] 缩略图
[search:pics] 多图
[search:content] 内容
[search:enclosure] 附件
[search:enclosuresize] 附件大小
[search:keywords] 关键词
[search:description] 描述
[search:istop] 是否置顶
[search:isrecommend] 是否推荐
[search:isheadline] 是否头条
[search:visits] 访问数量
[search:likes] 点赞数量
[search:oppose] 反对数量
[search:likeslink] 点赞链接
[search:opposelink] 反对链接


返回顶部