当前位置:首页 > 教程文章 > 织梦cms > 正文内容

织梦cms标题精准搜索方法

admin3年前 (07-06) 织梦cms

1、在 /plus/ 新建一个 so.php 文件

<?phprequire_once(dirname(__FILE__) . "/../include/common.inc.php");require_once DEDEINC . "/arc.partview.class.php";if ($title == ''){    ShowMsg('关键字不能为空!', '-1');    exit();}$row = $dsql->GetOne("SELECT id FROM `#@__archives` WHERE title = '$title' ");if (is_array($row)){    $chRow    = $dsql->GetOne("SELECT c.addtable FROM #@__archives AS a LEFT JOIN #@__channeltype AS c ON a.channel=c.id where a.id='{$row['id']}'");    $addtable = trim($chRow['addtable']);    $result   = $dsql->GetOne("SELECT arc.*,addf.* FROM `#@__archives` arc LEFT JOIN `{$addtable}` addf ON arc.id=addf.aid WHERE arc.arcrank>-1 AND arc.id = '{$row['id']}'");    $pv       = new PartView();    foreach ($result as $k => $v)    {        $pv->Fields[$k] = $v;    }    $pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . $cfg_df_style . "/so.htm");    $pv->Display();}else{    ShowMsg('没有相关记录!', '-1');}exit();

2、你的模板文件夹里添加1个 so.htm 模板文件

例如 /templets/default/so.htm

<div>    <p>标题:{dede:field.title /}</p>    <p>缩略图:{dede:field.litpic /}</p>    <p>品牌:{dede:field.pinpai /}</p>    <p>货号:{dede:field.huohao /}</p>    <p>价格:{dede:field.jiage /}</p>    <p>内容:{dede:field.body /}</p></div>

可调用所有字段包括自定义字段

3、前台模板搜索框代码

<form  method="post" action="{dede:global.cfg_cmspath/}/plus/so.php" >    <div id="search_box">        <p>标题精准搜索:<input type="text" name="title" value="" /></p>        <input type="submit" name="submit" value="开始搜索"  />    </div></form>

注意:name="title"   不是 name="q"

扫描二维码推送至手机访问。

版权声明:本文由EcmsDemo发布,如需转载请注明出处。

本文链接:http://bdk3521.eicp.vip/jiaocheng/dedecms/36.html

"织梦cms标题精准搜索方法" 的相关文章