用tag调用相关文章的方法在帝国官方论坛上有人发过方法,但所使用的函数效率太低而且无法制定参数,不好用。
一、自定义函数
自定义函数user_OtherLink ,将此函数放入 e\class\userfun.php 文件中。
//根据tag获取相关信息
function user_OtherLink($num,$classid=0,$mid=0){
global $dbtbpre,$empire,$navinfor,$class_r;
if(empty($navinfor['infotags'])){
return '暂无相关信息';
}
if($mid&&$classid&&$class_r[$classid]['modid']!=$mid){
return '暂无相关信息';
}
$tr=$empire->fetch1("select otherlinktemp,otherlinktempsub,otherlinktempdate from ".GetTemptb("enewspubtemp")." limit 1");
$temp_r=explode("[!--empirenews.listtemp--]",$tr['otherlinktemp']);
$str='';
$tagsql=$empire->query("select * from {$dbtbpre}enewstagsdata where id='$navinfor[id]' and classid='$navinfor[classid]'");
$i=0;
$isprint=array();
while($tagr=$empire->fetch($tagsql)){
if($i>=$num){
break;
}
$gsql=$empire->query("select * from {$dbtbpre}enewstagsdata where tagid='$tagr[tagid]'");
while($gr=$empire->fetch($gsql)){
$myprint='id'.$gr['id'].'class'.$gr['classid'];
if(array_search($myprint,$isprint)!==false){
continue;
}
$isprint[]=$myprint;
if($classid&&$classid!=$gr['classid']){
continue;
}
if($mid&&$mid!=$gr['mid']){
continue;
}
if($gr['id']==$navinfor['id']&&$gr['classid']==$navinfor['classid']){
continue;
}
$tbname=$class_r[$gr['classid']]['tbname'];
if(!$tbname||InfoIsInTable($tbname)){
continue;
}
$r=$empire->fetch1("select * from {$dbtbpre}ecms_".$tbname." where id='$gr[id]' limit 1");
if(!$r['id']){
continue;
}
$str.=RepOtherTemp($temp_r[1],$r,$tr);
$i+=1;
if($i>=$num){
break;
}
}
}
$keyboardtext=$temp_r[0].$str.$temp_r[2];
if($str){
return $keyboardtext;
}else{
return '暂无相关信息';
}
}
二、 使用方法:
函数说明:user_OtherLink(调用条数,指定栏目id,指定模型id) ;
相关文章模板采用的是公共模板里的相关信息模板。
调用示例:
<?=user_OtherLink(10,0,1)?>
声明:开发猫网络内所有作品,均为开发猫手写代码。部分样式或模板代码移植或仿造自互联网(如有侵权,出示著作权证书联系我删除),所有代码不能用于非法站点(色情,暴力,政治类站点)。开发猫网络只提供源代码服务,不提供任何建站服务。不承担任何建站后的法律问题!开发猫网络所得费用均为制作模板劳动报酬。使用开源免费的帝国CMS作为核心,请保留帝国CMS的版权。如商用请购买帝国商业版,开发猫网络只做帝国CMS模板服务,不做任何建站、不制作采集任何网站内容、不出售任何非开源有版权源代码更不卖任何域名和空间服务器,我出卖的只是我的技术劳动力!如在本站发生交易任何资源或者下载任何资源,则代表默认同意以上文字内容。感谢小伙本的支持,做一个知法守法的好公民!