帝国cms默认的[!–other.link–]标签调用相关链接时,如果没有相关链接的话,则会显示“暂无相关链接”。对于一些采集站或其他需要增加内链的网站来说,此时最好能调用本栏目的其它一些信息填充进来。这里分享一个自己用的函数,实现这个功能。
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;
}
当信息有相关信息时,调用相关信息,如果没有,则调用同栏目、当前信息前后100个id之内的信息中发布时间最靠近的,100可以设置成参数。将此函数放进 userfun.php 文件中,在模板中调用方法:
<?=dp_GetKeyboard(200)?>
这个函数满足我一个小站的功能,对于其它网站来说,补充调用信息可能比较简陋,可以自行修改。
1.本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:175495721@qq.com,我们将第一时间处理!
2.资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持
3.所有资源仅限于参考和学习,版权归原作者所有,更多请阅读网站声明。