软件简介: |
帝国CMS默认调用相关信息的标签为[otherlink]1,'',10,32,0,0,0[/otherlink],系统设置里面也可以选择调用相关的条件。但有个缺陷是不能跨表调用,而且如果调用信息没有就显示空白,不利于优化。
帝国cms相关信息截图
这个是本站的跨多表调用相关信息的效果,可以看到调用了新闻表的同时,也调用模板数据表的内容。
插件使用方法
以下代码复制粘贴进系统eclassuserfun.php文件中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
//跨表调用相关链接
//返回相关链接操作类型
function u_OtherLinkQuery( $classid , $line , $enews , $doing ){
global $empire , $public_r , $class_r , $class_zr , $navinfor , $dbtbpre , $eyh_r , $etable_r , $class_tr ;
if ( $enews ==1) //按表
{
if ( strstr ( $classid , ',' )) //多表
{
$tbr = explode ( ',' , $classid );
$duo =1;
}
else
{
$tbname = $classid ;
$duo =0;
}
}
elseif ( $enews ==2) //按栏目
{
if ( $classid == 'selfinfo' ) //当前栏目
{
$classid = $navinfor [ 'classid' ];
}
$tbname = $class_r [ $classid ][ 'tbname' ];
if ( $class_r [ $classid ][islast])
{
$and = "classid='$classid'" ;
}
else
{
$and =ReturnClass( $class_r [ $classid ][sonclass]);
}
}
elseif ( $enews ==3) //按标题分类
{
$tbname = $class_tr [ $classid ][ 'tbname' ];
$and = "ttid='$classid'" ;
}
else //默认
{
$tbname = $class_r [ $navinfor [classid]][ 'tbname' ];
}
//关键字
$keys = '' ;
if (! empty ( $enews ))
{
$repadd = '' ;
$keyr = explode ( ',' , $navinfor [ 'keyboard' ]);
$count = count ( $keyr );
for ( $i =0; $i < $count ; $i ++)
{
if ( $i ==0)
{
$or = '' ;
}
else
{
$or = ' or ' ;
}
$repadd .= $or . "[!--f--!] like '%" . $keyr [ $i ]. "%'" ;
}
//搜索范围
if ( $public_r [ 'newslink' ]==1)
{
$keys = '(' . str_replace ( '[!--f--!]' , 'keyboard' , $repadd ). ')' ;
}
elseif ( $public_r [ 'newslink' ]==2)
{
$keys = '(' . str_replace ( '[!--f--!]' , 'keyboard' , $repadd ). ' or ' . str_replace ( '[!--f--!]' , 'title' , $repadd ). ')' ;
}
else
{
$keys = '(' . str_replace ( '[!--f--!]' , 'title' , $repadd ). ')' ;
}
}
else
{
$keys = 'id in (' . $navinfor [ 'keyid' ]. ')' ;
}
//当前信息
if ( $tbname == $class_r [ $navinfor [classid]][tbname])
{
$and .= empty ( $and )? "id<>'$navinfor[id]'" : " and id<>'$navinfor[id]'" ;
}
//图片信息
if ( $doing )
{
$and .= empty ( $and )? "ispic=1" : " and ispic=1" ;
}
if ( $and )
{
$and .= ' and ' ;
}
if ( empty ( $line ))
{
$line = $class_r [ $navinfor [classid]][ 'link_num' ];
}
//优化
$yhvar = 'otherlink' ;
$yhid = $etable_r [ $tbname ][yhid];
$yhadd = '' ;
if ( $yhid )
{
$yhadd =ReturnYhSql( $yhid , $yhvar ,1);
}
if ( $duo ==0)
{
$query = "select * from {$dbtbpre}ecms_" . $tbname . " where " . $yhadd . $and . $keys . " order by newstime desc limit $line" ;
}
else
{
$nowtb = $class_r [ $navinfor [ 'classid' ]][ 'tbname' ];
$nowid = $navinfor [ 'id' ];
$query = '' ;
foreach ( $tbr as $n => $tbname ){
$t = $n +1;
if ( $tbname == $nowtb ){
$q . $n = "select title,titleurl,newstime,classid,titlepic from " . $dbtbpre . "ecms_" . $tbname . " where " . $yhadd . $and . $keys . " and (id>$nowid or id<$nowid) order by newstime desc limit " . $line ;
} else {
$q . $n = "select title,titleurl,newstime,classid,titlepic from " . $dbtbpre . "ecms_" . $tbname . " where " . $yhadd . $and . $keys . " order by newstime desc limit " . $line ;
}
$query .= 'select * from (' . $q . $n . ') t' . $t . ' union all ' ;
}
$query = substr ( $query ,0,-10). ' order by newstime desc limit ' . $line ;
}
$sql = $empire ->query1( $query );
if (! $sql )
{
echo "SQL Error: " .ReRepSqlTbpre( $query );
}
return $sql ;
}
//相关链接标签
function u_GetOtherLinkInfo( $tempid , $classid = '' , $line =0, $strlen =60, $have_class =0, $enews =0, $doing =0){
global $empire , $navinfor , $public_r ;
if ( empty ( $navinfor [ 'keyboard' ])||( empty ( $enews )&&! $navinfor [ 'keyid' ]))
{
return '' ;
}
$sql =u_OtherLinkQuery( $classid , $line , $enews , $doing );
if (! $sql )
{ return "" ;}
//取得模板
$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];
$docode = $tr [docode];
//替换变量
$listtemp =ReplaceEcmsinfoClassname( $listtemp , $enews , $classid );
if ( empty ( $rownum ))
{ $rownum =1;}
//字段
$ret_r =ReturnReplaceListF( $tr [modid]);
//列表
$list_exp = "[!--empirenews.listtemp--]" ;
$list_r = explode ( $list_exp , $listtemp );
$listtext = $list_r [1];
$no =1;
$changerow =1;
while ( $r = $empire ->fetch( $sql ))
{
$r [oldtitle]= $r [title];
//替换列表变量
$repvar =ReplaceListVars( $no , $listvar , $subnews , $strlen , $formatdate , $url , $have_class , $r , $ret_r , $docode );
$listtext = str_replace ( "<!--list.var" . $changerow . "-->" , $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 ;
} |
后台-模板-标签-导入附件中的mylink.bq文件
前台调用方法
1 |
[mylink]标签模板ID,操作对象,调用条数,标题截取字数,是否显示栏目名,操作类型,只显示标题图片的信息[/mylink] |
标签模板ID:查看标签模板ID点这里
操作对象:对应操作类型的表/栏目/专题。空则为默认。
操作类型:0为默认;1为按表(多个表格式:'news,photo');2为按栏目;3为按标题分类
是否显示栏目名:0为不显示;1为显示
只显示标题图片的信息:0为不限;1为只显示标题图片的信息
调用实例
1 |
[mylink]2, 'news,download,photo,flash,movie,shop,article,info' ,10,32,0,1,0[/mylink] |
标签模板id——2
调用的跨表——news,download,photo,flash,movie,shop,article,info
调用条数——10
截取标题——32
不显示栏目名——0
按数据表调用——1
不限图片属性——0
|