最近在搞帝國CMS,如果文章包含圖片,或者文章是置頂的,需要在列表的題頭顯示相應的標識,后來用靈動標簽實現了,這里記錄一些,估計會有不少人會用到。
我們以3天內的發布為條件輸出帶 new 圖標的信息(首頁模板上的靈動標簽格式):
[e:loop={欄目ID,顯示條數,操作類型,只顯示有標題圖片}]<?$newimg=""; if(time()-$bqr[truetime]<=3*24*3600) {$newimg="<img src='New圖片地址'>"; }?><li><a href="<?=$bqsr[titleurl]?>" title="<?=$bqr[title]?>" target="_blank"><?=esub($bqr[title],36)?></a><?=$newimg?></li>[/e:loop]
注:字段值數組變量為$bqr,對應的字段變量為$bqr[字段名],如:標題字段變量就是$bqr[title]。
首先在列表模板上勾選"使用程序代碼",我們以推薦為條件輸出帶 new 圖標的信息(列表頁模板 【列表內容模板(list.var) 】上的格式):
$newimg="; if($r[isgood]==1) {$newimg='<img src='New圖片地址'>';}$listtemp='<li><a href="[!--titleurl--]" title="[!--oldtitle--]">[!--title--]</a>'.$newimg.'</li>';
注:字段值數組變量為$r,對應的字段變量為$r[字段名],如:標題字段變量就是$r[title]。另外定義的變量為'.$newimg.' 。將最終模板內容賦給$listtemp變量。
更多首頁模板上的條件收集:
if($bqr[isgood]==1) //推薦 if($r[firsttitle]==1) //頭條 if($r[istop]==1) //置頂 if($bqr[isgood]==1&&$bqr[firsttitle]==1&&$bqr[istop]==1) //置頂-頭條-推薦 (組合使用)
最后給出實際使用中的代碼:
[e:loop={'selfinfo',20,0,0}]<?$newimg="";$good="";if(!empty($bqr[titlepic])){ $newimg="<img src='http://www.zzarea.com/bbs/static/image/filetype/image_s.gif' />";}if($bqr[istop]==1){ $good = "<img src='http://www.zzarea.com/bbs/static/image/common/pin_1.gif' />";}?> <tr class="even"> <td class="title"> <h1><a href="<?=$bqsr[titleurl]?>" target="_blank"><?=sub($bqr[title],0,30,false)?></a> <?=$newimg?> <?=$good?></h1> <p class="intro"> <?=sub($bqr[smalltext],0,80,false)?>[<a title="閱讀全文" href="<?=$bqsr[titleurl]?>" target="_blank">詳細內容</a>] </p> </td> <td><?=$bqr[myarea]?></td> <td><?=date('Y-m-d H:i:s', $bqr[newstime])?></td> </tr>[/e:loop]
新聞熱點
疑難解答