更多



June 11, 2019

 以下代码写入/e/class/userfun.php文件内

XML/HTML代码
        
  1. function user_otherlink($limit=5){  
  2.     
  3.         global $dbtbpre,$empire,$navinfor,$class_r;  
  4.     
  5.     if($navinfor[infotags]){  
  6.     
  7.             $classid=(int)$classid;  
  8.     
  9.         $limit=(int)$limit;  
  10.     
  11.         $tbname=$class_r[$navinfor[classid]][tbname];  
  12.     
  13.         $tagarr=explode(",",$navinfor[infotags]);  
  14.     
  15.         $arr=array();  
  16.     
  17.         $num=ceil($limit/count($tagarr));  
  18.     
  19.         foreach($tagarr as $k=>$v){  
  20.     
  21.                         if(count($tagarr)==$k+1){  
  22.     
  23.                                 $num=$limit-count($arr);  
  24.     
  25.                         }else{  
  26.     
  27.                                 if($i<$num){  
  28.     
  29.                                         $num=ceil(($limit-count($arr))/count($tagarr));  
  30.     
  31.                                 }                  
  32.     
  33.                         }  
  34.     
  35.             $t=$empire->fetch1("select tagid,num from {$dbtbpre}enewstags where tagname='$v'");  
  36.     
  37.                         if($t[tagid]){  
  38.     
  39.                                 $sql=$empire->query("select id from {$dbtbpre}enewstagsdata where tagid=$t[tagid]");  
  40.     
  41.                                 $i=0;  
  42.     
  43.                                 while($s=$empire->fetch($sql)){  
  44.     
  45.                                         if(in_array($s[id],$arr)||$s[id]==$navinfor[id]){  
  46.     
  47.                                                 continue;  
  48.     
  49.                                         }else{  
  50.     
  51.                                                 $arr[]=$s[id];  
  52.     
  53.                                                 $i++;  
  54.     
  55.                                         }  
  56.     
  57.                                         if($i==$num){  
  58.     
  59.                                                 break;  
  60.     
  61.                                         }  
  62.     
  63.                                         if(count($arr)==$limit){  
  64.     
  65.                                                 break 2;  
  66.     
  67.                                         }  
  68.     
  69.                                 }  
  70.     
  71.                                 if($t[num]>$num){  
  72.     
  73.                                         $linshi=$t[tagid];  
  74.     
  75.                                 }  
  76.     
  77.                         }   
  78.     
  79.         }  
  80.     
  81.         if(count($arr)>0){  
  82.     
  83.                         $inid=implode(",",$arr);  
  84.     
  85.                         if(count($arr)<$limit&&$linshi){  
  86.     
  87.                                 $sql=$empire->query("select id from {$dbtbpre}enewstagsdata where tagid=$linshi and id not in($inid)");  
  88.     
  89.                                 while($s=$empire->fetch($sql)){  
  90.     
  91.                                         $arr[]=$s[id];  
  92.     
  93.                                         if(count($arr)==$limit){  
  94.     
  95.                                                 break;  
  96.     
  97.                                         }  
  98.     
  99.                                 }  
  100.     
  101.                         }  
  102.     
  103.                         $inid=implode(",",$arr);  
  104.     
  105.                         $str="";  
  106.     
  107.                         $news=$empire->query("select id,title,titleurl,titlepic,newstime from {$dbtbpre}ecms_{$tbname} where id in($inid)");  
  108.     
  109.                         while($n=$empire->fetch($news)){  
  110.     
  111.                                 //用date参数格式化日期  
  112.     
  113.                                 $now = $n[newstime];  
  114.     
  115.                                 $str.='<li><span class="point"></span><a href="'.$n[titleurl].'">'.$n[title].'</a><div>'.date("m-d",$now).'</div></li>';  
  116.     
  117.                         }          
  118.     
  119.                 }  
  120.     
  121.         return $str;  
  122.     
  123.            }  
  124.     
  125. }  

在内容页模板用以下代码调用:

XML/HTML代码
        
  1. <?=user_otherlink(5)?>  

5为显示数量,可自行修改

From: 本站原创
Tags:
0 Comment(s)
发表评论
昵称
密码 [ 游客无需密码 ]
电邮
网址
打开HTML 打开UBB 打开表情 隐藏 记住我