帝国CMS相关信息为空时调用其它信息方法

MoBan5源码 | 2022-06-21 11:59:44 |

帝国cms系统默认的[!--other.link--]标签调用相关文章链接为空时会显示“暂无相关链接”这样在网站内链和显示上不太友,最好能调用本栏目的其它一些信息填充进来。

下面我们通过增加一个函数来实现这个功能,方法很简单也很实用。

增加判断当信息有相关信息时调用相关信息,如果没有则调用同栏目、当前信息前后100个id之内的信息中发布时间最靠近的,当然100可以设置成参数自己根据需求进行修改。

将以下自定义函数内容加入到userfun.php 文件中:

function dp_GetKeyboard($num=100){ 
global $empire,$public_r,$class_r,$fun_r,$dbtbpre,$class_r,$navinfor; 
$keyid=$navinfor['keyid']; 
$classid=$navinfor['classid']; 
$id=$navinfor['id']; 
$link_num=$class_r[$classid]['link_num']; 
if(!$link_num){ 
return $fun_r['NotLinkNews']; 

$tr=$empire->fetch1("select otherlinktemp,otherlinktempsub,otherlinktempdate from ".GetTemptb("enewspubtemp")." limit 1"); 
$temp_r=explode("[!--empirenews.listtemp--]",$tr[otherlinktemp]); 
if($keyid){ 
$add="id in (".$keyid.")"; 
}else{ 
$e=$id+$num; 
$s=$id-$num; 
$add=" classid=".$classid." and id>".$s." and id<".$e; 

$key_sql=$empire->query("select id,newstime,title,isurl,titleurl,classid,titlepic from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where ".$add." order by newstime desc limit $link_num"); 
while($link_r=$empire->fetch($key_sql)){ 
if($link_r['id']==$id){ 
continue; 

$keyboardtext.=RepOtherTemp($temp_r[1],$link_r,$tr); 

if(empty($keyboardtext)){ 
return $fun_r['NotLinkNews']; 

$keyboardtext=$temp_r[0].$keyboardtext.$temp_r[2]; 
return $keyboardtext; 

在模板中调用标签:<!--?=dp_getkeyboard(200)?-->

更具体的可以根据自己的需求进行修改,上面可以做为一个参考希望对大家有用。

以上就是帝国CMS相关信息为空时调用其它信息方法。
 


标签:相关信息