织梦cms标题精准搜索方法
1、在 /plus/ 新建一个 so.php 文件
<?php require_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"
本文结束