帝国系统的标签在e/class/t_functions.php,前缀是sys_
用户自定义的标签一般写在e/class/userfun.php文件的函数名,函数命名请以”user_”开头
如果系统定义的标签满足不了你现在的需求可以再自定义一个。比如说:想通过
showclasstemp(带模板的栏目导航标签)来获取bclassid,但是改函数不支持,为了实现需求,对其标签再次编写改造,如下:
//带模板的栏目导航标签 function user_ShowClass($classid, $tempid, $show = 0, $cline = 0) { global $navclassid, $empire, $class_r, $public_r, $dbtbpre; //当前栏目 if ($classid == "selfinfo") { if (empty($navclassid)) { $classid = 0; } else { $classid = $navclassid; //终极类别则显示同级类别 if ($class_r[$classid][islast] && $class_r[$classid][bclassid]) { $classid = $class_r[$classid][bclassid]; } if ($class_r[$classid][islast] && empty($class_r[$classid][bclassid])) { $classid = 0; } } } //取得模板 $tr = sys_ReturnBqTemp($tempid); if (empty($tr['tempid'])) { return ""; } $listtemp = str_replace('[!--news.url--]', $public_r[newsurl], $tr[temptext]); $subnews = $tr[subnews]; $listvar = str_replace('[!--news.url--]', $public_r[newsurl], $tr[listvar]); $rownum = $tr[rownum]; $formatdate = $tr[showdate]; if (empty($rownum)) { $rownum = 1; } //限制条数 if ($cline) { $limit = " limit " . $cline; } //替换变量 $bclassname = $class_r[$classid][classname]; $br[classid] = $classid; $bclassurl = sys_ReturnBqClassname($br, 9); $listtemp = str_replace("[!--bclassname--]", $bclassname, $listtemp); $listtemp = str_replace("[!--bclassurl--]", $bclassurl, $listtemp); $listtemp = str_replace("[!--bclassid--]", $classid, $listtemp); //列表 $list_exp = "[!--empirenews.listtemp--]"; $list_r = explode($list_exp, $listtemp); $listtext = $list_r[1]; $no = 1; $changerow = 1; $sql = $empire->query("select classid,bclassid,classname,islast,sonclass,tbname,intro,classimg,infos from {$dbtbpre}enewsclass where bclassid='$classid' and showclass=0 order by myorder,classid" . $limit); while ($r = $empire->fetch($sql)) { //显示类别数据数 if ($show) { $num = ReturnClassInfoNum($r); } //替换列表变量 $repvar = userReplaceShowClassVars($no, $listvar, $r, $num, 0, $subnews); $listtext = str_replace("", $repvar, $listtext); $changerow += 1; //超过行数 if ($changerow > $rownum) { $changerow = 1; $string .= $listtext; $listtext = $list_r[1]; } $no++; } //多余数据 if ($changerow <= $rownum && $listtext != $list_r[1]) { $string .= $listtext; } $string = $list_r[0] . $string . $list_r[2]; echo $string; } //替换栏目导航标签 function userReplaceShowClassVars($no, $listtemp, $r, $num, $ecms = 0, $subnews = 0) { global $public_r, $class_r; //栏目链接 if ($ecms == 1) { $classurl = sys_ReturnBqZtname($r); $r['classname'] = $r['ztname']; $r['classid'] = $r['ztid']; $r['classimg'] = $r['ztimg']; } else { $classurl = sys_ReturnBqClassname($r, 9); } if ($subnews) { $r[intro] = sub($r[intro], 0, $subnews, false); } $listtemp = str_replace("[!--classurl--]", $classurl, $listtemp); //栏目名称 $listtemp = str_replace("[!--classname--]", $r[classname], $listtemp); //栏目id $listtemp = str_replace("[!--classid--]", $r[classid], $listtemp); //栏目图片 if (empty($r[classimg])) { $r[classimg] = $public_r[newsurl] . "e/data/p_w_picpaths/notimg.gif"; } $listtemp = str_replace("[!--classimg--]", $r[classimg], $listtemp); //栏目简介 $listtemp = str_replace("[!--intro--]", nl2br($r[intro]), $listtemp); //记录数 $listtemp = str_replace("[!--num--]", $num, $listtemp); //序号 $listtemp = str_replace("[!--no--]", $no, $listtemp); $listtemp = str_replace("[!--bclassid--]", $r[bclassid], $listtemp); return $listtemp; }
1、改造sql:
$sql = $empire->query("select classid,bclassid,classname,islast,sonclass,tbname,intro,classimg,infos from {$dbtbpre}enewsclass where bclassid='$classid' and showclass=0 order by myorder,classid" . $limit);
2、替换模板:因为想调取bclassid,但是bclassid不存在,对此进行替换
$listtemp = str_replace("[!--bclassid--]", $r[bclassid], $listtemp);
注:不必担心userfun.php中得函数在帝国系统中找不到,这个文件已经被t_functions引入了。