织梦CMS(Content Management System)是一种广泛使用的开源内容管理系统,适用于企业网站、个人博客等多种场景,在企业网站中,特别是产品类别繁多的情况下,用户经常需要选择栏目类别进行定点搜索,本文将详细介绍如何在织梦CMS中实现这一功能,并提供相关的FAQs。
一、使用Channelartlist标签实现栏目搜索
1、基本代码示例:
<form action="{dede:field name='phpurl'/}/search.php" name="formsearch">
<div class="form">
<input type="hidden" name="kwtype" value="0" />
<input name="keyword" type="text" class="searchkeyword" id="searchkeyword" />
<select name="typeid" class="searchoption" id="typeid">
<option value="0" selected="selected" class="searchxl">全部栏目</option>
{dede:channelartlist typeid='top'}
{dede:type}
<option value="[field:id/]">[field:typename/]</option>
{/dede:type}
{dede:channel type='son' noself='yes'}
<option value="[field:id/]">[field:typename/]</option>
{/dede:channel}
{/dede:channelartlist}
</select>
<button type="submit" class="searchsubmit">站内搜索</button>
</div>
</form>
2、代码解析:
{dede:field name='phpurl'/}
:获取当前网站的URL。
<input type="hidden" name="kwtype" value="0" />
:隐藏字段,用于指定搜索类型。
<input name="keyword" type="text" class="searchkeyword" id="searchkeyword" />
:输入框,用于输入搜索关键词。
<select name="typeid" class="searchoption" id="typeid">
:下拉选择框,用于选择要搜索的栏目。
<option value="0" selected="selected" class="searchxl">全部栏目</option>
:默认选项,表示搜索所有栏目。
{dede:channelartlist typeid='top'}
:调用顶级栏目。
{dede:type}
和{dede:channel type='son' noself='yes'}
:分别调用顶级栏目和子栏目。
<button type="submit" class="searchsubmit">站内搜索</button>
:提交按钮,触发搜索。
1、修改表单提交:
<form name="formsearch" action="/plus/search.php">
<input type="hidden" name="typeid" value="1,2,3">
</form>
2、修改PHP文件:
打开/plus/search.php
文件,找到并删除以下代码:
$typeid = (isset($typeid) && is_numeric($typeid)) ? $typeid : 0;
$typeid = intval($typeid);
打开/include/arc.searchview.class.php
文件,找到并修改以下代码:
$ksqls[] = " typeid IN (".GetSonIds($this>TypeID).") ";
改为:
//指定了多个栏目时
if( preg_match('#,#', $this>TypeID) )
{
$typeids = explode(',', $this>TypeID);
foreach($typeids as $ttid) {
$typeidss[] = GetSonIds($ttid);
}
$typeidStr = join(',', $typeidss);
$typeidss = explode(',', $typeidStr);
$typeidssok = array_unique($typeidss);
$typeid = join(',', $typeidssok);
$ksqls[] = " arc.typeid IN ($typeid) ";
}
else
{
$ksqls[] = " arc.typeid IN (".GetSonIds($this>TypeID).") ";
}
1、问题1:如何在织梦CMS中实现全站搜索?
答案1:在织梦CMS中实现全站搜索,可以使用内置的搜索功能,只需在搜索表单中不指定typeid
参数,即可实现全站搜索。
<form action="{dede:field name='phpurl'/}/search.php" method="get">
<input type="text" name="q" placeholder="请输入关键词" />
<input type="submit" value="搜索" />
</form>
2、问题2:如何定制搜索结果页面的样式?
答案2:定制搜索结果页面的样式可以通过修改模板文件来实现,搜索结果页面的模板文件位于/templets/default/search.htm
,你可以在此文件中添加或修改HTML和CSS代码,以实现所需的样式效果,可以在模板文件中添加以下代码来自定义搜索结果的显示方式:
<ul>
{dede:search typeid='all' pagesize='10'}
<li>
<a href='[field:title/][field:id/].html'>[field:title/]</a>
<p>[field:description function="cn_substr(@me,100)"/]</p>
</li>
{/dede:search}
</ul>