帝國CMS 列表模板listvar支援程式碼

來源:互聯網
上載者:User
1、增加模板時list.var模板需要勾選“使用程式碼”選項。

2、直接添加PHP代碼,不需要加

list.var模板範例:
例子1:如果資訊沒有設定標題圖片就顯示指定的圖片。

1if(empty($r[titlepic]))2{3        $r[titlepic]='/images/img.gif';4}5 $listtemp='<li><a href="[!--titleurl--]"><img src="[!--titlepic--]">a>li>';

說明:$r[titlepic]為標題圖片欄位變數。$listtemp為模板內容變數。

例子2:如果資訊是今天發布的就顯示&ldquo;NEW&rdquo;圖片標識。

1$newimg='';2 if(time()-$r[newstime]<=1*24*3600)3{4        $newimg='<img src="NEW圖片地址" border="0">';5}6 $listtemp='<li><a href="[!--titleurl--]">[!--title--]a> '.$newimg.'li>';

說明:$r[newstime]為發布時間欄位變數。$listtemp為模板內容變數。

例子3:調用投稿使用者的公司名稱。

1$userr=$empire->fetch1("select company from {$dbtbpre}enewsmemberadd where userid='$r[userid]' limit 1");2 $listtemp='<li><a href="[!--titleurl--]">[!--title--]a><span>公司名稱:'.$userr[company].'span>li>';

說明:$r[userid]為發行者使用者ID欄位變數。$listtemp為模板內容變數。

其他說明:
如果$listtemp引用模板內容是用單引號,那麼裡面使用單引號前面要加\,例如:$listtemp='<img src=\'[!--titlepic--]\'>';
相反如果引用模板內容是用雙引號,那麼裡面使用雙引號前面也要加\,例如:$listtemp="<img src=\"[!--titlepic--]\">";
支援程式碼可以實現很多非常複雜的應用需求。

以上就介紹了帝國CMS 列表模板listvar支援程式碼,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.