首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> PHP 程式設計 >> PHP 相關知識

PHPCMS V9 模板標籤技巧大全:常用調用方法總結

     編輯:PHP 相關知識

PHPCMS V9 模板開發常用代碼匯總

1. 截取標題長度

{str_cut($r[title], 36, '')}  // 後面引號為去掉省略號

2. 格式化時間輸出

{date('Y-m-d H:i:s', $r[inputtime])}  // 輸出:2011-05-06 11:22:33

3. 多欄目 & 多推薦位聯合調用

{pc:get sql="SELECT * FROM v9_news WHERE id IN (SELECT id FROM v9_position_data WHERE posid in(27,28) and catid in(59,60,61)) order by listorder DESC" cache="3600" start="3" num="7" return="data"}
{loop $data $n $r}
  
  • ·{str_cut($r[title],22,'')}
  • {/loop} {/pc}

    說明:文章範圍為欄目 59/60/61,推送至推薦位 27/28,從第 3 條開始取 7 篇。

    4. 顯示欄目名稱(含/不含連結)

    {$catname}  // 僅名稱
    {$CATEGORYS[$r['catid']]['catname']}  // 含連結
    

    5. 獲取父欄目資訊

    {$CATEGORY[$catid][parentid]}  // 父欄目 ID
    {$CATEGORYS[$CAT[parentid]][catname]}  // 父欄目名稱
    

    6. 外部資料源調用

    {pc:get sql="SELECT * FROM cq_member where mtype='企業'" cache="3600" dbsource="dedecmsdb" num="7" return="data"}
    {loop $data $r}
      {str_cut($r[uname],28,'')}
    {/loop}
    {/pc}
    

    需在後台「資料源」添加 dedecmsdb 配置。

    7. 調用子欄目(欄目首頁適用)

    {pc:content action="category" catid="$catid" num="25" siteid="$siteid" order="listorder ASC"}
    {loop $data $r}
      {$r[catname]} |
    {/loop}
    {/pc}
    

    8. 指定 ID 顯示欄目名稱

    {$CATEGORYS[22]['catname']}  // 例:catid=22
    

    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--'}
    

    12. 從指定位置開始調用

    {pc:content action="position" posid="27" order="listorder DESC" num="3" start="5"}
    // 相當於 LIMIT 5,3
    

    13. 文章列表調用關鍵字

    {pc:content action="lists" catid="$catid" num="10" order="id DESC" page="$page"}
    {loop $data $r}
      {$r[title]}
      {php $keywords = explode(',', $r[keywords]);}
      文章標簽:
      {loop $keywords $keyword}
        {$keyword}
      {/loop}
    {/loop}
    {/pc}
    

    注意:explode(',', ...) 依英文逗號分割。若關鍵字用空格分隔,改為 explode(' ', ...)。

    14. 每 N 行插入分隔符(如直線 |)

    {pc:content action="position" posid="8" order="listorder DESC" num="2"}
    {loop $data $r}
      {str_cut($r[title],26,'')}{if $n%2==1} |{/if}
    {/loop}
    {/pc}
    

    15. 列表頁完美支援自定義欄位

    {pc:content action="lists" catid="$catid" num="25" order="id DESC" page="$page" moreinfo="1"}
    {loop $data $r}
      [{$r['字段名']}] {$r[title]}
    {/loop}
    
    {$pages}
    {/pc}

    16. 當前欄目調用父級及以下所有欄目資訊

    {php $arrchildid = $CATEGORYS[$CAT[parentid]][arrchildid]}
    {pc:get sql="SELECT * FROM v9_news where catid in($arrchildid)" cache="3600" page="$page" num="12" return="data"}
    

    17. V9 表單提交後返回當前頁(而非首頁)

    修改 phpcms/modules/formguide/index.php 第 73 行:

    // 原
    showmessage(L('thanks'), APP_PATH);
    // 改
    showmessage(L('thanks'), HTTP_REFERER);
    

    18. 首頁/列表頁自定義欄位調用

    {pc:content action="lists" moreinfo=1 catid="2" order="id DESC" num="4"}
    
      {loop $data $key $val}
    • {$val['title']}
      價格:{str_cut($v['自定義段'],100)}
    • {/loop}
    {/pc}

    推薦位調用同理,需在模型勾選「在推薦位標籤中調用」,且新增文章後需更新才生效。

    20. 編輯器上傳圖片自動用標題作為 alt

    修改 statics/js/ckeditor/plugins/image/dialogs/image.js:

    // 找到
    accessKey:'T','default':''
    // 替換為
    accessKey:'T','default':$('#title').val()
    

    清除瀏覽器快取後生效。

    21. 文章隨機點擊數增加

    修改 phpcms/modules/content/classes/content_output.class.php 約 100 行:

    $rand_nums = rand(79, 186);
    $views = $r['views'] + $rand_nums;
    // 點擊一次增加 79~186 隨機數
    

    22. 常見版本 Bug 民間修復

    • 縮略圖/圖集無法上傳:phpcms/libs/classes/attachment.class.php 第 24 行 $this->upload_func = 'copy'; → 'move_uploaded_file'
    • 碎片模組搜尋文章看不到欄目:phpcms/modules/block/templates/search_content.tpl.php 第 13 行修正 form::select_category 參數

    23. PHPCMS V9 get 標籤完整用法

    支援內部/外部資料、分頁、自定義返回變量、跨資料庫調用。關鍵技巧:ORDER BY B.comments DESC LIMIT 3,7 可實現「跳過前 2 條評論最多的文章,取第 3-9 條」,解決縮略圖比例不佳問題。

    1. 上一篇文章:
    2. 下一篇文章:
    Copyright © 程式碼之家 All Rights Reserved