帝国CMS 8.0搜索结果页修复:支持灵动标签与标题高亮
众所周知,帝国 CMS 8.0 的模板搜索结果列表页原生不支持 SQL 查询、灵动标签等各类调用标签。 将下方代码复制至 e/search/result/index.php 文件中即可修复该限制,同时实现搜索关键词标题高亮效果。
代码如下:
<?php
require("../../class/connect.php");
require("../../data/dbcache/class.php");
//require("../../class/q_functions.php");
require("../../class/functions.php");
require('../../class/t_functions.php');
require "../" . LoadLang("pub/fun.php");
$editor = 1;
eCheckCloseMods('search'); //关闭模块
$link = db_connect();
$empire = new mysqlquery();
$getvar = $_GET['getvar'];
if (empty($getvar)) {
$getfrom = "history.go(-1)";
} else {
$getfrom = "../../../search/";
}
//搜索结果
$searchid = (int)$_GET['searchid'];
if (empty($searchid)) {
printerror("SearchNotRecord", $getfrom, 1);
}
//搜索用户组
if ($public_r['searchgroupid']) {
include('../../member/class/user.php');
@include("../../data/dbcache/MemberLevel.php");
$user = islogin();
$mvgresult = eMember_ReturnCheckMVGroup($user, $public_r['searchgroupid']);
if ($mvgresult <> 'empire.cms') {
printerror("NotLevelToSearch", $getfrom, 1);
}
}
$search_r = $empire->fetch1("select searchid,keyboard,result_num,orderby,myorder,tbname,tempid,andsql,trueclassid from {$dbtbpre}enewssearch where searchid='$searchid'");
if (empty($search_r['searchid']) || InfoIsInTable($search_r['tbname'])) {
printerror("SearchNotRecord", $getfrom, 1);
}
if (!eInfoHaveTable($search_r['tbname'], 0)) {
printerror("SearchNotRecord", $getfrom, 1);
}
$search_r['tempid'] = (int)$search_r['tempid'];
$page = (int)$_GET['page'];
$page = RepPIntvar($page);
$start = 0;
$page_line = (int)$public_r['search_pagenum']; //每页显示链接数
$line = (int)$public_r['search_num']; //每页显示记录数
$offset = $page * $line; //总偏移量
if ($offset > $public_r['searchupnum']) {
printerror("SearchNotRecord", $getfrom, 1);
}
$search = "&searchid=" . $searchid;
$myorder = $search_r['orderby'];
if (empty($search_r['myorder'])) {
$myorder .= " desc";
}
$add = stripSlashes($search_r['andsql']);
$num = $search_r['result_num'];
if (strstr($add, "") || strstr($search_r['andsql'], "")) {
exit();
}
//ids
$pageids = eGetidsLimitMlen($search_r['andsql'], 10, $line, $page, 1);
if (!$pageids) {
printerror("SearchNotRecord", $getfrom, 1);
}
$query = "select * from {$dbtbpre}ecms_" . $search_r['tbname'] . " where id in (" . $pageids . ")";
//$query.=" order by ".$myorder."".do_dblimit($line,$offset);
$query .= " order by " . $myorder . "";
$sql = $empire->query($query);
$listpage = page1($num, $line, $page_line, $start, $page, $search);
//取得模板
if ($search_r['tempid']) {
$tempr = $empire->fetch1("select temptext,subnews,listvar," . do_dbkeyfield_spe('rownum') . ",showdate,modid,subtitle,docode from " . GetTemptb("enewssearchtemp") . " where tempid='" . $search_r['tempid'] . "'" . do_dblimit_one());
} elseif (empty($class_r[$search_r['trueclassid']]['searchtempid'])) {
$tempr = $empire->fetch1("select temptext,subnews,listvar," . do_dbkeyfield_spe('rownum') . ",showdate,modid,subtitle,docode from " . GetTemptb("enewssearchtemp") . " where isdefault=1" . do_dblimit_one());
} else {
$tempr = $empire->fetch1("select temptext,subnews,listvar," . do_dbkeyfield_spe('rownum') . ",showdate,modid,subtitle,docode from " . GetTemptb("enewssearchtemp") . " where tempid='" . $class_r[$search_r['trueclassid']]['searchtempid'] . "'" . do_dblimit_one());
}
$have_class = 1;
//替换公共模板变量
$tempr['temptext'] = DtNewsBq('listsearch' . $search_r['tempid'], $tempr['temptext'], 0);
$listtemp = $tempr['temptext'];
if ($public_r['searchtempvar']) {
$listtemp = ReplaceTempvar($listtemp);
}
$search_r['keyboard'] = ehtmlspecialchars($search_r['keyboard']);
$listtemp = str_replace("[!--show.page--]", $listpage, $listtemp);
$listtemp = str_replace("[!--keyboard--]", $search_r['keyboard'], $listtemp);
$listtemp = str_replace("[!--ecms.num--]", $num, $listtemp);
$url = "<a href='" . ReturnSiteIndexUrl() . "'>" . $fun_r['index'] . "</a> > " . $fun_r['adsearch'];
$pagetitle = $fun_r['adsearch'] . " " . $search_r['keyboard'];
$listtemp = ReplaceSvars($listtemp, $url, 0, $pagetitle, $pagetitle, $pagetitle, $addr, 0);
$rownum = $tempr['rownum'];
if (empty($rownum)) {
$rownum = 1;
}
$formatdate = $tempr['showdate'];
$subnews = $tempr['subnews'];
$subtitle = $tempr['subtitle'];
$docode = $tempr['docode'];
$modid = $tempr['modid'];
$listvar = str_replace('[!--news.url--]', $public_r['newsurl'], $tempr['listvar']);
//字段
$ret_r = ReturnReplaceListF($tempr['modid']);
//取得列表模板
$list_exp = "[!--empirenews.listtemp--]";
$list_r = explode($list_exp, $listtemp);
$listtext = $list_r[1];
$no = $offset + 1;
$changerow = 1;
while ($r = $empire->fetch($sql)) {
//替换列表变量
$r['title'] = str_replace($search_r['keyboard'], "<font color='red'>{$search_r['keyboard']}</font>", $r['title']);
$repvar = ReplaceListVars($no, $listvar, $subnews, $subtitle, $formatdate, $url, $have_class, $r, $ret_r, $docode);
$listtext = str_replace("<!--list.var" . $changerow . "-->", $repvar, $listtext);
$changerow += 1;
//超过行数
if ($changerow > $rownum) {
$changerow = 1;
$string .= $listtext;
$listtext = $list_r[1];
}
$no++;
}
db_close();
$empire = null;
//多余数据
if ($changerow <= $rownum && $listtext <> $list_r[1]) {
$string .= $listtext;
}
$string = $list_r[0] . $string . $list_r[2];
echo stripSlashes($string);
帝国CMS教程
帝国CMS 8.0搜索结果页修复:支持灵动标签与标题高亮
帝国CMS 8.0默认搜索结果列表页不支持SQL查询、灵动标签等调用,通过修改e/search/result/index.php,引入函数文件并调整查询,即可正常使用各类标签,同时实现搜索关键词在标题中的红色高亮。本文提供完整可用代码。
帝国CMS图片水印不支持webp格式解决办法
本文为一组PHP图像处理函数,主要实现图片缩放与加水印功能。ResizeImage函数可按指定宽高及比例对图片进行裁剪或缩放,支持jpg、png、gif、webp等格式。imageWaterMark函数可为背景图添加图片或文字水印,支持九种位置定位和透明度控制,兼容多种图片格式。
亲测可用帝国CMS完美无报错Sitemap
一、个人实测踩坑总结最近给帝国CMS站点配置网站地图,踩了一大堆坑,要么报PHP version语法错误,要么XML格式不
帝国CMS图片裁剪Cannot read properties of null (ReloadChangeFilePage)
最近搭建、维护帝国CMS站点的朋友,基本都会遇到一个兼容性bug:新版Chrome/Edge浏览器后台图片裁剪、选择已上
帝国CMS插件
未找到合适的帝国 CMS 成品插件?
如有定制需求,或是想优化现有插件功能,欢迎随时联系沟通。
微信
QQ
15年开发经验
自己做过站长,深知站长痛点
独立开发
自己编码、测试、维护,不是二道贩子
持续迭代
根据用户真实反馈持续优化
代码透明
核心逻辑清晰,不加密、不混淆
售后保障
提供安装指导和技术支持,随时响应
联系方式
微信 / QQ 即时沟通