咨询电话:13667221916 24小时服务热线:13667221916
NEWS CENTER ·
公司动态
关注我们 关注前沿

CxCms搜索功能实战代码

发表日期:2020-12-12 14:59:00    文章编辑:admin    

简单搜索网站内容

<form action="search.asp" method="get">
<input type="text" name="keys">
<input type="submit" value="提交搜索">
</form>

       传入一个name为“keys”的参数即可完成搜索,对应的模板文件是search.html文件。


不同类型的内容搜索

<form action="search.asp" method="get">
<input type="text" name="keys">
<input name="searchtype" type="hidden" value="类型ID">
<input type="submit" value="提交搜索">
</form>

       除了keys外,额外传了一个“searchtype”的值,该指可以是2、3、4、5、6、8,分别代表文章、产品、下载、招聘、相册、视频。此时如果需要对不同的类型显示不同的搜索结果样式,可以创建search类型ID.html文件,例如创建search2.html,那么搜索文章时就会调用该模板,如果对应类型搜索模板不存在,则使用默认的search.html文件。


搜索指定栏目的内容

<form action="search.asp" method="get">
<input type="text" name="keys">
<input name="searchsort" type="hidden" value="栏目ID">
<input type="submit" value="提交搜索">
</form>

       这个搜索是要传一个searhsort的参数,给想要搜索的栏目ID就可以了。


多条件联合搜索内容

<form action="search.asp" method="get">
<input type="text" name="keys">
<input name="searchmuti" type="hidden" value="Author,Content">
<input type="text" name="Author" value="作者关键词">
<input type="text" name="Content" value="内容关键词">
<input type="submit" value="提交搜索">
</form>

       上述例子,首先要传一个“searchmuti”的参数,其value指是内容现有的字段,自定义字段也可参数搜索,然后加了哪些字段搜索,额外的再提供这些字段的搜索值即可进行多条件搜索。keys不是必须的,keys的搜索只是标题和内容描述。这个代码运行后就会搜索作者名称符合作者关键词,并且内容符合指定关键词的内容,如果需要完全等于,则传值时需要在内容前跟上“=”,同理如果需要比较大小时,前面需要带上“>”或者“<”。

图片.png

<form action="/search.asp" method="get">
<input name="searchtype" type="hidden" value="3">
<label class="layui-form-label">名称:</label>
<div class="layui-input-inline">
<input type="text" name="keys" value="{cxcms:keys}" class="layui-input">
</div>
<input name="searchmuti" type="hidden" value="P_mbid,P_mbprice,P_mbwap">
<label class="layui-form-label">编号:</label>
<div class="layui-input-inline">
<input type="text" name="P_mbid" value="{cxcms:P_mbid}" class="layui-input">
</div>
<label class="layui-form-label">价格:</label>
<div class="layui-input-inline">
<input type="text" name="P_mbprice" value="{cxcms:P_mbprice}" class="layui-input">
</div>
<label class="layui-form-label" style="width: 70px;">手机版:</label>
<div class="layui-input-inline" style="width: 90px;margin-right:15px;">
<select name="P_mbwap">
<option value="">不限</option>
<option value="=含有" {if:"{cxcms:P_mbwap}"="=含有"}selected{end if}>含有</option>
<option value="=不含有" {if:"{cxcms:P_mbwap}"="=不含有"}selected{end if}>不含有</option>
</select>

多条件模糊搜索

     与多条件联合搜索相比,联合搜索是所有搜索参数都一一对应匹配,而模糊搜索是多条件匹配一个关键词,由一对一变成了多对一。

<form action="search.asp" method="get">
<input type="text" name="keys">
<input name="searchmuti" type="hidden" value="Author,Content">
<input type="hidden" name="Author" value="null_">
<input type="hidden" name="Content" value="null_">
<input type="submit" value="提交搜索">
</form>

      传入一个“searchmuti”的参数,里面对应自己要搜索哪些参数字段,然后里面提到的参数都传“null_”,再加上keys参数,达到的效果是搜索keys时,author或者content符合条件的结果,常用于例如一个输入框,输入关键词后,搜索产品名称、货号、配置信息满足一条即显示的情况。


      在搜索结果页可以使用的标签有

标签
释义
备注
{cxcms:topsortid}
顶级栏目ID
当传入searchsort时,该值等于searchsort栏目的顶级ID,否则为0
{cxcms:parentsortid}父级栏目ID
当传入searchsort时,该值等于searchsort栏目的父级ID,否则为0
{cxcms:sortid}栏目ID
当传入searchsort后,该值等于searchsort,否则为0
{cxcms:searchtype}
搜索类型
结果有2、3、4、5、6、8
{cxcms:searchsort}
搜索栏目ID
searchsort的值
{cxcms:keys}
搜索关键字
keys的值
{cxcms:****}
自定义搜索条件时对应的值
配合searchmuti使用时会用到
{cxcms:sortname}
栏目名称
显示“搜索结果”



contact us

13667221916

  • 电话:13667221916
  • 邮箱:1613310013@qq.com
  • 网址:http://www.chixiao123.com
  • 地址:湖北省武汉市江夏区阳光大道东方雨林8栋403

友情链接: 众考教育 | 赤霄网络 |

武汉赤霄网络科技有限公司  备案号:鄂ICP备14013644号-1鄂公网安备 42011102001670号 电子亮照: