0712-2888027 189-8648-0214
微信公眾號

孝感風(fēng)信網(wǎng)絡(luò)科技有限公司微信公眾號

當(dāng)前位置:主頁 > 技術(shù)支持 > PHPCMS > phpcms v9模板標(biāo)簽技巧,標(biāo)簽調(diào)用方法大全

phpcms v9模板標(biāo)簽技巧,標(biāo)簽調(diào)用方法大全

時間:2024-09-19來源:風(fēng)信官網(wǎng) 點(diǎn)擊: 841次

1.截取調(diào)用標(biāo)題長度

{str_cut($r[title],36,'')}

2.格式化時間

調(diào)用格式化時間 2011-05-06 11:22:33

{date('Y-m-d H:i:s',$r[inputtime])}

3.多欄目調(diào)用&多推薦位調(diào)用

調(diào)用需求:文章范圍為59 60 61三個欄目,并且推送到了27 和28兩個推薦位;
從第三條開始,連續(xù)調(diào)用7篇文章。

{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}
<li>·<a target="_blank" href='{$r[url]}' title="{$r[title]}" style="color:Black;">{str_cut($r[title],22,'')}</a></li>
{/loop}
{/pc}

4.顯示欄目名稱(只是名稱,不帶鏈接)

{$catname}

顯示欄目名稱和鏈接(可以點(diǎn)擊)

<a href="{$CATEGORYS[$r[catid]][url]}">{$CATEGORYS[$r['catid']]['catname']}</A>

5.獲取父欄目id/獲取父欄目名稱

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

6.外部數(shù)據(jù)源調(diào)用

dedecmsdb 在后臺數(shù)據(jù)源處添加
{pc:get sql="SELECT * FROM cq_member where mtype='企業(yè)' " cache="3600" dbsource="dedecmsdb" num="7" return="data"}
{loop $data $r}
<a href="/member/index.php?uid={$r[userid]}" title="{$r[uname]}" target="_blank">{str_cut($r[uname],28,'')}</a>
{/loop}
{/pc}

7.調(diào)用子欄目(在欄目首頁模板需要用到)

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

8.顯示指定id的欄目名稱 (例子這里catid=22)

{$CATEGORYS[22]['catname']}

9.在文章面前顯示文章類別

{pc:content action="lists" catid="79" order="listorder DESC" num="14" }
<?php $TYPE = getcache('type_content','commons');?>
{loop $data $n $r}
<li>{if $TYPE[$r[typeid]][name]}<span style="color:#CC6600">[ {$TYPE[$r[typeid]][name]}] </span>{/if}<a href="{$r['url']}"{title_style($r[style])}title="{$r['title']}" target="_blank">{str_cut($r[title],33,'')}</a></li>
{/loop}
{/pc}

10.指定變量循環(huán)增長(幻燈片經(jīng)常用到)

{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.文章調(diào)用使用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}
<li><a href="{$r[url]}" title="{$r[title]}" target=_blank>{str_cut($r[title],36,'')}</a></li>
{/loop}
{/pc}

12.文章從指定位置開始調(diào)用

起始位置為5,調(diào)用3條。相當(dāng)于limit功能。
{pc:content  action="position" posid="27" order="listorder DESC" num="3" start="5"}
{loop $data $r}
<a  href='{$r[url]}'>{str_cut($r[description],115)}... </a>
{/loop}
{/pc}

13.文章列表頁調(diào)用關(guān)鍵字,或者首頁調(diào)用關(guān)鍵字
注意:explode(',',$r[keywords]);是將文章關(guān)鍵詞通過英文逗號分離,也就是說每一篇文章都要以逗號間隔關(guān)鍵字,否則調(diào)用出來會 是全部作為一個關(guān)鍵字。如果是空格間隔關(guān)鍵字,將explode(',',$r[keywords]);改成explode(' ',$r[keywords]);

{pc:content action="lists" catid="$catid" num="10" order="id DESC" page="$page"}
{loop $data $r}
<a href="{$r[url]}">{$r[title]}</a>
{php $keywords = explode(',',$r[keywords]);}
<b>文章標(biāo)簽:</b>
{loop $keywords $keyword}
<a  href="{APP_PATH}index.php?m=content&c=tag&catid={$catid}&tag={urlencode($keyword)}" class="blue"> {$keyword}</a>
{/loop}
{/loop}
{/pc}

14.每當(dāng)列表幾行的時候出現(xiàn)一次某些符號(比如首頁里面的文章推薦,一行顯示兩條,在這兩條中間想加一條豎線 | 就用到這個代碼了)

數(shù)量大的話就容易出錯,因?yàn)槟_\(yùn)算嘛~~呵呵 不過一般也就4個標(biāo)題以下
{pc:content  action="position" posid="8" order="listorder DESC" num="2"}
{loop $data $r}
<a style="color:#040605" title="{$r[title]}" href="{$r[url]}" target=_blank>{str_cut($r[title],26,'')}</a>{if $n%2==1} |{/if}
{/loop}
{/pc}

15.v9 列表頁完美支持自定義段調(diào)用

{pc:content action="lists" catid="$catid" num="25" order="id DESC" page="$page" moreinfo="1"}
{loop $data $r}
<a href="{$r[url]}">[{$r['字段名']}]> {$r[title]}</a>
{/loop}
<div class="pagebar">{$pages}</div>
{/pc}

16.當(dāng)前欄目調(diào)用父級及以下欄目信息方法

其他代碼 該咋地還是要咋地 。這是要素
{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表單功能 提交之后如何返回當(dāng)前頁面,而不是默認(rèn)的首頁文件地址
找到 phpcms\modules\formguide\index.php文件第73行

showmessage(L('thanks'), APP_PATH);

修改成 如下代碼即可實(shí)現(xiàn)自動返回前一頁

showmessage(L('thanks'), HTTP_REFERER);

18.v9 首頁或分頁自定義字段調(diào)用
和15差不多
第一普通列表或欄目調(diào)用自定義字段
在{pc:content  action="lists" 后加上副表moreinfo=1 (等于1時顯示,0時不顯示)
例子:

{pc:content  action="lists" moreinfo=1 catid="2" order="id DESC" num="4"}
<ul>
{loop $data $key $val}
<li><a href="{$val['url']}">{$val['title']}</a>
<br>價(jià)格:{str_cut($v['自定義段'],100)}    //100 是字?jǐn)?shù)
</li>
{/loop}
</ul>
{/pc}

第二種推薦位調(diào)用自定義字段
在模型里加好自定義字段后,必須把“在推薦位標(biāo)簽中調(diào)用”點(diǎn)擊“是“
然后用同一樣的方法去調(diào)節(jié)數(shù)據(jù)就OK了,記住,如果你加了文章,必須去更新文章才會顯示,自定義段在推薦中只顯示你選擇后,選擇前加的加文章不顯示,更新一下文章就顯示了
例子:

{pc:content action="position" posid="推薦位id" num="30" thumb="1" moreinfo="1" order="listorder DESC"}
{loop $data $key $val}
<LI><a href="{$val['url']}" target="_blank"><img src="{$val['自定義段']}" alt="{$val['title']}" height=36 width=98 /></a>
<a href="{$val['url']}" target="_blank">{str_cut($val['title'],20)}</a></LI>
{/loop}
{/pc}

20.編輯器上傳圖片自動使用標(biāo)題作為alt參數(shù)

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

找到

accessKey:'T','default':''

替換成

accessKey:'T','default':$('#title').val()

二: 清除瀏覽器緩存

21.增加文章的隨機(jī)點(diǎn)擊數(shù)

找到100行的$views = $r['views'] +1
修改為:
$rand_nums=rand(79,186);

$views = $r['views'] + $rand_nums;

表示點(diǎn)擊一次,增加79到186次不等

-------------------------------------------------------------
tips:某些版本出錯民間解決方法
1.縮略圖以及圖集無法上傳
\phpcms\libs\classes\attachment.class.php
請把24行的(也有可能是23行)
$this->upload_func = 'copy';
改成
$this->upload_func = 'move_uploaded_file';

2.碎片模塊搜索文章看不到欄目
phpcms\modules\block\templates\search_content.tpl.php
13行改成

<td><?php
if(isset($_GET['dosubmit'])){?><div class="rt"><a
href="javascript:void(0)" onclick="$('#search').toggle()"><?php
echo L('folded_up_in_search_of')?></a></div><?php }
echo form::select_category('', $catid, 'name="catid" id="catid"', '',
'', '0', 1)?> </td>

22、PHPCMS V9的get標(biāo)簽調(diào)用

1、調(diào)用本系統(tǒng)單條數(shù)據(jù),示例(調(diào)用ID為1的信息,標(biāo)題長度不超過25個漢字,顯示更新日期):
{get sql="select * from phpcms_content where contentid=1" /}
標(biāo)題:{str_cut($r[title], 50)} URL:{$r[url]} 更新日期:{date('Y-m-d', $r[updatetime])}
2、調(diào)用本系統(tǒng)多條數(shù)據(jù),示例(調(diào)用欄目ID為1通過審核的10條信息,標(biāo)題長度不超過25個漢字,顯示更新日期):
{get sql="select * from phpcms_content where catid=1 and status=99 order by updatetime desc" rows="10"}
標(biāo)題:{str_cut($r[title], 50)} URL:{$r[url]} 更新日期:{date('Y-m-d', $r[updatetime])}
{/get}
3、帶分頁,示例(調(diào)用欄目ID為1通過審核的10條信息,標(biāo)題長度不超過25個漢字,顯示更新日期,帶分頁):
{get sql="select * from phpcms_content where catid=1 and status=99 order by updatetime desc" rows="10" page="$page"}
標(biāo)題:{str_cut($r[title], 50)} URL:{$r[url]} 更新日期:{date('Y-m-d', $r[updatetime])}
{/get}
分頁:{$pages}
4、自定義返回變量,示例(調(diào)用欄目ID為1通過審核的10條信息,標(biāo)題長度不超過25個漢字,顯示更新日期,返回變量為 $v):
{get sql="select * from phpcms_content where catid=1 and status=99 order by updatetime desc" rows="10" return="v"}
標(biāo)題:{str_cut($v[title], 50)} URL:{$v[url]} 更新日期:{date('Y-m-d', $v[updatetime])}
{/get}
5、調(diào)用同一帳號下的其他數(shù)據(jù)庫,示例(調(diào)用數(shù)據(jù)庫為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、調(diào)用外部數(shù)據(jù),示例(調(diào)用數(shù)據(jù)源為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}

不知道有沒有朋友在使用中遇到這幾種方法不能滿足需求的時候呢?

例 如:取出評論數(shù)最多的第3條到第10條記錄,有人說我是多此一舉,一般取最多評論沒理由不取第一和第二條,因?yàn)镻HPCMS的縮略圖對4:3這樣 的尺寸比較好,對長條形(如3:4)的圖片縮略效果不好,為了自己手動更新評論最多的第一和第二條記錄,故此不想自動更新讀取前兩條。

<ul>
<!--{get sql="select A.contentid,A.catid,A.title,A.thumb,A.description,A.url,A.status,A.updatetime,B.contentid,B.hits,B.comments from `phpcms_content` as A INNER JOIN `phpcms_content_count` as B ON A.contentid=B.contentid and A.status=99 and LENGTH(A.thumb)>0 order by B.comments desc LIMIT 3,7"}-->
<li><span class="xxnse_fen2">{$r[comments]}人參與評論</span>·<a href="{$r[url]}" title="{$r[title]}">{str_cut($r[title], 28)}</a></li>
<!--{/get}-->
</ul>

關(guān)鍵點(diǎn)就在 order by B.comments desc LIMIT 3,7 (表示從第3條記錄開始,向下讀取7條數(shù)據(jù))這個在MYSQL是經(jīng)常用,我抱著試試看的想法,結(jié)果是可以的。

效果如下:

希望做PHPCMS開發(fā)的朋友共同學(xué)習(xí)和分享

phpcms V9 保留了2008的get標(biāo)簽的使用方法

它包括了2種方式一種是內(nèi)部數(shù)據(jù),另一種是外部數(shù)據(jù)

我們先分析下內(nèi)部數(shù)據(jù)的使用方法

1、內(nèi)部數(shù)據(jù)的調(diào)用

{pc:get sql="SELECT * FROM `XX` WHERE  fid =$ltid AND digest =2 AND ifupload =1 ORDER BY tid DESC" num="2" cache= "3600" return="data" }
{loop $data $r}

。。。。。

{/loop}{/pc}

由此可以看出  get 語句支持num的用法但是不支持 limit 5,5.這樣的用法

實(shí)在是很遺憾

num是調(diào)用的條數(shù)

2、外部數(shù)據(jù)的調(diào)用

{ pc : get sql = "SELECT * FROM phpcms_member" cache = "3600" page = "$page" dbsource = "discuz" return = "data" }

<ul>

{ loop $data $key $val }

{ $val [ username ]}< br />

{ /loop}

</ ul >

{ $pages }

{/ pc }

一個是數(shù)據(jù)源,一個是產(chǎn)生的pages翻頁效果

欄目列表
推薦內(nèi)容
熱點(diǎn)內(nèi)容
展開