PHPCMS GET標籤使用

來源:互聯網
上載者:User

標籤:

大綱:

get 標籤概述
get 標籤文法
get 標籤建立工具
get 調用本系統樣本
get 調用其他系統樣本
一、get 標籤概述
    通俗來講,get 標籤是Phpcms定義的能直接調用資料庫裡面內容的簡單化、友好化代碼,她可調用本系統和外部資料,只有你對SQL有一定的瞭解,她就是你的絕世好劍!也就是適合熟悉SQL語句的人使用。有了她,我們打造個人化的網站,能非常方便的調用出資料庫裡面指定的內容。通過條件限制,我們可以調用出不同條件下的不同資料。
二、get標籤樣式
{get dbsource=" " sql=" "}
{/get}
三、get 標籤文法
1.get標籤屬性值必須用雙引號括起來( " " )。
例如:
{get sql=" " /}
2.get標籤必須含有結束標記,即正確get標籤必須是成對出現:整個Get標籤含有結束標記“ {/get}”,或者是“/”。
3.get標籤裡面含有的變數,數組和函數必須用“{}”包括。
例如:
{str_cut($r[title], 50)}
{$r[url]}
4.get標籤 sql語句中條數限制。( rows=" " )
例如:顯示10條資訊
{get sql=" " rows="10"}
{/get}
5.get標籤 sql語句中條件限制。( where )
例如:調用欄目ID為1的資訊
{get sql="select * from phpcms_content where catid=1"}
標題:{$r[title]} URL:{$r[url]} 
{/get}
6.get標籤 sql語句中排序。( order by )
例如:按更新日期降序(desc)排列
{get sql="select * from phpcms_content order by updatetime desc" }
{$r[title} URL:{$r[url]}
{/get}
7.get標籤裡面嵌套php函數。(可以參考上面的第3點)
例如:格式化輸出時間戳記
{date(‘Y-m-d‘, $r[updatetime])}
8.本系統資料調用(當前資料庫調用)
{get sql=""}
{/get}
或者
{get sql="" return="r"}
{/get}
9.本系統資料調用10條
{get sql="" rows="10"}
{/get}
10.同一個資料庫帳號的不同資料庫調用
{get dbname="" sql="" }
{/get}
11.不同資料庫帳號調用(不同資料來源調用)
{get dbsource="" sql=""}
{/get}
12.不同資料庫帳號的不同資料庫調用
{get dbsource="" dbname="" sql="" }
{/get}
13.本系統資料調用,帶分頁
{get sql=" " page="$page"}
{/get}
分頁:{$pages}
14.本系統資料調用,自訂返回變數
{get sql=" " return="v"}
{$v[ ]}
{/get}
*get 標籤參數完整剖析
{get dbsource="資料來源" dbname="資料庫" sql="SQL語句" rows="行數" return="返回變數名稱" page="$page"}
輸出代碼(含返回變數值、數組、函數等)
{/get}
dbname="資料庫" -->
(資料庫 在添加資料來源的時候需要填寫的資料庫名)
註:本系統調用(同一資料庫帳號,同一資料庫名)可以省略
sql="SQL語句" -->
SQL語句可以參考Mysql手冊,上面get 標籤文法第4、5、6點和SQL語句剖析已經提及要點
註:此參數不可以省略
rows="行數" -->
行數,例如顯示10條資訊:rows="10"
註:此參數可以省略
return="返回變數名稱" -->
參考get 標籤文法第8點和第14點
註:此參數可以省略
page="$page" -->
帶分頁
註:此參數可以省略
*SQL語句剖析
sql="select 欄位 from 表名 where 條件運算式 order by 欄位 desc/asc"
6條完整get 標籤程式碼範例
    1.調用本系統單條資料,樣本(調用ID為1的資訊,標題長度不超過25個漢字,顯示更新日期):
    {get sql="select * from phpcms_content where contentid=1" /}
    標題:{str_cut($r[title], 50)} URL:{$r[url]} 更新日期:{date(‘Y-m-d‘, $r[updatetime])}
    2.調用本系統多條資料,樣本(調用欄目ID為1通過審核的10條資訊,標題長度不超過25個漢字,顯示更新日期):
   {get sql="select * from phpcms_content where catid=1 and status=99 order by updatetime desc" rows="10"}
    標題:{str_cut($r[title], 50)} URL:{$r[url]} 更新日期:{date(‘Y-m-d‘, $r[updatetime])}
   {/get}
    3.帶分頁,樣本(調用欄目ID為1通過審核的10條資訊,標題長度不超過25個漢字,顯示更新日期,帶分頁):
    {get sql="select * from phpcms_content where catid=1 and status=99 order by updatetime desc" rows="10" page="$page"}
   標題:{str_cut($r[title], 50)} URL:{$r[url]} 更新日期:{date(‘Y-m-d‘, $r[updatetime])}
    {/get}
    分頁:{$pages}
   4.自訂返回變數,樣本(調用欄目ID為1通過審核的10條資訊,標題長度不超過25個漢字,顯示更新日期,返回變數為 $v):
    {get sql="select * from phpcms_content where catid=1 and status=99 order by updatetime desc" rows="10" return="v"}
   標題:{str_cut($v[title], 50)} URL:{$v[url]} 更新日期:{date(‘Y-m-d‘, $v[updatetime])}
{/get}
5.調用同一帳號下的其他資料庫,樣本(調用資料庫為bbs,分類ID為1的10個最新主題,主題長度不超過25個漢字,顯示更新日期):
{get dbname="bbs" sql="select * from cdb_threads where fid=1 order by dateline desc" rows="10"}
主題:{str_cut($r[subject], 50)} URL:http://bbs.phpcms.cn/viewthread.php?tid={$r[tid]} 更新日期:{date(‘Y-m-d‘, $r[dateline])}
{/get}
6.調用外部資料,樣本(調用資料來源為bbs,分類ID為1的10個最新主題,主題長度不超過25個漢字,顯示更新日期):
{get dbsource="bbs" sql="select * from cdb_threads where fid=1 order by dateline desc" rows="10"}
主題:{str_cut($r[subject], 50)} URL:http://bbs.phpcms.cn/viewthread.php?tid={$r[tid]} 更新日期:{date(‘Y-m-d‘, $r[dateline])}
{/get}
四、get 標籤建立工具
1、擷取get 標籤代碼

例如,剛才我們資料來源選擇“本系統”,資料表選擇“內容模型”,欄位名我們顯示“ID、標題、摘要、連結地址、發布時間”,條件選擇ID=1,排序按ID降序排序,勾選“是否分頁”,每頁顯示條數設定為“10條”,然後點擊“插入”

我們就可以得到系統自動產生的get 標籤代碼,如下:

{get sql="SELECT `contentid`,`title`,`description`,`url`,`inputtime` FROM `phpcms_content` WHERE `contentid` = ‘1‘ ORDER BY `contentid` DESC"rows="10" page="$page" }
{$r[contentid]}
{$r[title]}
{$r[description]}
{$r[url]}
{$r[inputtime]}
{/get}
{$pages}
分析如下:
{get sql="SELECT `contentid`,`title`,`description`,`url`,`inputtime` FROM ` phpcms_content`" WHERE `contentid` = ‘1‘ ORDER BY `contentid` DESC rows="10" page="$page" }
//條件是ID=1,排序按ID降序排序,顯示10行,帶分頁

{$r[contentid]}
// ID

{$r[title]}
//標題

{$r[description]}
//摘要

{$r[url]}
//連結地址

{$r[inputtime]}
//發布時間
{/get}
{$pages}
//分頁
2、將代碼插入到模板檔案
get 標籤代碼如下:
{get dbsource="discuz" sql="SELECT `author`,`subject`,`lastpost` FROM `cdb_threads` ORDER BY `lastpost` DESC" rows="3" }
{$r[author]}
{$r[subject]}
{$r[lastpost]}
{/get}


更多網站公告
在上面加入(稍加美化的get 標籤代碼):

論壇最新文章

 

 

{get dbsource="discuz" sql="SELECT `author`,`subject`,`lastpost` FROM `cdb_threads` ORDER BY `lastpost` DESC" rows="3" }
({$r[author]}){str_cut($r[subject], 22,"")} date:{date("Y-m-d",$r[lastpost])}

{/get}

PHPCMS GET標籤使用

聯繫我們

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