phpCMS 慣用代碼(一)

來源:互聯網
上載者:User
phpCMS 常用代碼(一)
1.去掉標題限制後出現的省略符號
{str_cut($r[title],36,'')}

2.格式化時間 2011-05-06 11:22:33
{date('Y-m-d H:i:s',$r[inputtime])}

3.格式化時間 2011年05月06日
{date('Y年m月d日',$r[inputtime])}

4.顯示欄目名稱(只是名稱,不帶連結)
{$catname}

5.顯示欄目名稱和連結(可以點擊)
{$CATEGORYS[$r['catid']]['catname']}

6.外部資料源調用
{pc:get sql="SELECT * FROM pre_forum_thread" cache="3600" dbsource="discuz" return="data" num="10"}

7.調用子欄目(在欄目首頁模板需要用到)
{pc:content action="category" catid="$catid" num="25" siteid="$siteid" order="listorder ASC"}{loop $data $r}
{$r[catname]} | {/loop}{/pc}

8.顯示指定id的欄目名稱 (例子這裡catid=22)
{$CATEGORYS[22]['catname']}

9.在文章面前顯示文章類別
{pc:content action="lists" catid="79" order="listorder DESC" num="14" }

{loop $data $n $r}
  • {if $TYPE[$r[typeid]][name]}[ {$TYPE[$r[typeid]][name]}] {/if}{str_cut($r[title],33,'')}

  • {/loop}{/pc}

    10.指定變數迴圈增長(投影片經常用到)
    {pc:content action="lists" catid="66" order="listorder DESC" thumb="1" num="5" }
    {php $num = 0}
    {loop $data $r}
    linkarr[{$num}] = "{$r[url]}";
    picarr[{$num}] = "{$r[thumb]}";
    textarr[{$num}] = "{str_cut($r[title],36,'')}";
    {php $num++}
    {/loop}
    {/pc}

    11.文章調用使用limit
    {pc:content action="position" posid="36" num="1" order="listorder DESC limit 1,1--" }
    其他都是跟以前一樣使用
    {pc:content action="position" posid="31" order="listorder DESC" limit='1,8--'}
    {loop $data $r}
  • {str_cut($r[title],36,'')}

  • {/loop}

    {/pc}


    12.phpCMS連結查詢
    {pc:get sql="SELECT * FROM v9_news a join v9_news_data b on a.id=b.id where catid=27" cache="3600" page="$page" return="data"}


      {loop $data $key $val}
    • {$val[title]}

    • {/loop}

    {if $pages}{$pages}{/if}
    {/pc}
    {$val[content]}


    13.phpCMS上一篇、下一篇
    上一篇:{$previous_page[title]}

    下一篇:{$next_page[title]}

    注意:a標籤裡面不能有target=“_blank”會發生錯誤。


  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.