做了个模板,用到专题输出判断,具体逻辑如下:
内容模板中分两段判断,
1、当前信息如果有所属专题,则输出当前内容页所属专题
2、如果以上条件不满足,则输出默认专题
代码附上:
<?php
$classname = $class_r[$navinfor['classid']]['classname'];
?>
<div class="detailCont_left5">
<p class="csTlt_1 csTlt_2"><span>相关专题</span><a href="/zt/" class="more" target="_blank" title=""><em>更多</em><i class="icon"></i></a></p>
<div class="tabBar">
<!--1111-->
<?php
$ecms_bq_sql = sys_ReturnEcmsLoopBq('select * from phome_enewsztinfo where classid=' . $navinfor['classid'] . ' and id=' . $navinfor['id'], 10, 24, 0);
$bqno = 0;
$hasOutput = false; // 添加一个变量来记录第一段代码是否有输出
while ($bqr = $empire->fetch($ecms_bq_sql)) {
$bqsr = sys_ReturnEcmsLoopStext($bqr);
$bqno++;
?>
<?php //加入php代码
if ($bqno == 1) { //指定第一条信息
$class1 = "current"; //第一条信息的样式
} else { //其它信息
$class1 = "tabs__item"; //其它信息的样式
}
?>
<span class="<?=$class1?>"> <?=$class_zr[$bqr['ztid']]['ztname']?></span>
<?php
$hasOutput = true; // 如果第一段代码有输出,将变量设为true
}
?>
<!--1111 end-->
<!--2222-->
<?php
if (!$hasOutput) { // 如果第一段代码没有输出,则执行第二段代码
$ecms_bq_sql = sys_ReturnEcmsLoopBq('select * from phome_enewszt order by addtime limit 4',4,24,1);
$bqno = 0;
while ($bqr = $empire->fetch($ecms_bq_sql)) {
$bqsr = sys_ReturnEcmsLoopStext($bqr);
$bqno++;
?>
<?php //加入php代码
if ($bqno == 1) { //指定第一条信息
$class1 = "current"; //第一条信息的样式
} else { //其它信息
$class1 = "tabs__item"; //其它信息的样式
}
?>
<span class="<?=$class1?>"> <?=$bqr['ztname']?></span>
<?php
}
}
?>
<!--2222 end-->
</div>
<?php
$classname1 = $class_r[$navinfor['classid']]['classname'];
?>
<div class="ulBox">
<!--1111-->
<?php
$ztsql = $empire->query("select a.*,b.* from {$dbtbpre}enewszt a,{$dbtbpre}enewsztinfo b where a.ztid=b.ztid and b.id='".$navinfor[id]."'");
$bqno = 0;
$hasOutput = false; // 判断第一段是否有输出值
while ($ztr = $empire->fetch($ztsql)) {
if ($class_zr[$ztr['ztid']]['ztid'] == $ztr['ztid']) {
$ztname = $class_zr[$ztr['ztid']]['ztname']; //专题名称
$ztlink = sys_ReturnBqZtname($ztr); //专题链接
$bqno++;
if ($bqno == 1) { //指定第一条信息
$class = ""; //第一条信息的样式
} else { //其它信息
$class = "hide"; //其它信息的样式
}
?>
<div class="<?=$class?>">
<div class="top">
<a href="<?=$ztlink?>" title="<?=$ztname?>" target="_blank" class="imgBox">
<img src="<?=sys_ResizeImg($ztr[ztimg], 80, 80, 1, '')?>" alt="<?=$ztname?>">
<span>共收录<?=$ztr[ztnum]?>款</span>
</a>
<p><?=$ztname?></p>
<span><?=date("Y-m-d", $ztr['addtime'])?></span>
<div>
<p><?=$ztr[intro]?></p>
<a href="<?=$ztlink?>" target="_blank" title="">查看详情<i class="icon"></i></a>
</div>
</div>
<ul>
<?php
$v = $ztr['ztid'];
?>
<?php
$ecms_bq_sql2=sys_ReturnEcmsLoopBq("select id,ztid,classid from [!db.pre!]enewsztinfo where ztid='$v' limit 21",0,24,0);
$bqno2=0;
while($bqr2=$empire->fetch($ecms_bq_sql2))
{
$id=($bqr2[id]);
$bqno2++;
?>
<?php
$ecms_bq_sql3=sys_ReturnEcmsLoopBq("select titleurl,title,classid,titlepic from {$dbtbpre}ecms_{$class_r[$bqr2[classid]][tbname]} where id={$bqr2[id]}",0,24,0);
$bqno3=0;
while($bqr3=$empire->fetch($ecms_bq_sql3))
{
$bqsr3=sys_ReturnEcmsLoopStext($bqr3);
$bqno3++;
?>
<li>
<a href="<?=$bqr3[titleurl]?>" target="_blank" title="<?=$bqr3[title]?>">
<img data-src="<?=$bqr3[titlepic]?>" src="" alt="<?=$bqr3[title]?>">
<p><?=$bqr3[title]?></p>
<p><?=$bqr3[classname]?></p>
<div >下载</div>
</a>
</li>
<?php
}
?>
<?php
}
?>
</ul>
</div>
<?php
$hasOutput = true; // 第一段有输出值
}
}
?>
<!--1111 end-->
<!--2222-->
<?php
if (!$hasOutput) { // 第一段没有输出值时执行第二段代码
$ecms_bq_sql=sys_ReturnEcmsLoopBq("select addtime,ztid,ztnum,ztimg,ztpath,ztname,intro from [!db.pre!]enewszt limit 4",0,24,0);
$bqno=0;
while($bqr=$empire->fetch($ecms_bq_sql))
{
$ztid=($bqr[ztid]);
$bqno++;
if ($bqno==1){ //指定第一条信息
$class = ""; //第一条信息的样式
}
else{ //其它信息
$class = "hide"; //其它信息的样式
}
?>
<div class="<?=$class?>">
<div class="top">
<a href="/<?=$bqr['ztpath']?>/" title="<?=$bqr['ztname']?>" target="_blank" class="imgBox">
<img src="<?=$bqr['ztimg']?>" alt="<?=$bqr['ztname']?>"/>
<span>共收录<?$num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsztinfo where ztid='$bqr[ztid]'");
echo $num;?>款</span>
</a>
<p><?=$bqr['ztname']?></p><span><?=date("Y-m-d",$bqr[addtime])?></span>
<div>
<p><?=$bqr['intro']?></p>
<a href="/<?=$bqr['ztpath']?>/" target="_blank" title="">查看详情<i class="icon"></i></a>
</div>
</div>
<ul>
<?php
$ecms_bq_sql2=sys_ReturnEcmsLoopBq("select id,ztid,classid from [!db.pre!]enewsztinfo where ztid='$ztid' limit 10",0,24,0);
$bqno2=0;
while($bqr2=$empire->fetch($ecms_bq_sql2))
{
$id=($bqr2[id]);
$bqno2++;
?>
<?php
$ecms_bq_sql3=sys_ReturnEcmsLoopBq("select titleurl,title,classid,titlepic from {$dbtbpre}ecms_{$class_r[$bqr2[classid]][tbname]} where id={$bqr2[id]}",0,24,0);
$bqno3=0;
while($bqr3=$empire->fetch($ecms_bq_sql3))
{
$bqsr3=sys_ReturnEcmsLoopStext($bqr3);
$bqno3++;
?>
<li>
<a href="<?=$bqr3[titleurl]?>" target="_blank" title="<?=$bqr3[title]?>">
<img data-src="<?=$bqr3[titlepic]?>" src="" alt="<?=$bqr3[title]?>">
<p><?=$bqr3[title]?></p>
<p><?=$bqr3[classname]?></p>
<div >下载</div>
</a>
</li>
<?php
}
?>
<?php
}
?>
</ul>
</div>
<?php
}
}
?>
<!--2222 end-->
</div>
</div>