Home > Article > Backend Development > phpcms v9 template tag skills, common methods of tags_PHP tutorial
A collection of commonly used codes for phpcms v9 template production
1. Intercept the call title length
{str_cut($r[title],36,'')}, the following quotation marks are to remove....
2.Formatting time
Call formatting time 2011-05-06 11:22:33
{date('Y-m-d H:i:s',$r[inputtime])}
3. Calling multiple columns & calling multiple recommendations
Calling requirements: The article ranges from three columns: 59, 60, and 61, and is pushed to two recommendation positions: 27 and 28;
Starting from the third article, 7 articles are called continuously.
{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}
{$catname}
Show column name and link (can be clicked)
{$CATEGORYS[$r['catid']]['catname']}
5. Get the parent column id/get the parent column name
{$CATEGORY[$catid][parentid]}
Parent column name: {$CATEGORYS[$CAT[parentid]][catname]}
6. External data source call
dedecmsdb is added at the background data source
{pc:get sql="SELECT * FROM cq_member where mtype='enterprise' " cache="3600" dbsource="dedecmsdb" num="7" return="data"}
{loop $data $r}
{str_cut($r[uname], 28,'')}
{/loop}
{/pc}
7. Call sub-column (need to be used in the column homepage template)
{pc:content action="category" catid="$catid" num="25" siteid="$siteid" order="listorder ASC"}
{loop $data $r}
{$r[catname]} |
{/loop}
{/pc}
8. Display the column name of the specified id (example here catid=22)
{$CATEGORYS[22]['catname']}
9. Display the article category in front of the article
{pc:content action="lists" catid="79" order="listorder DESC" num="14" }
{loop $data $n $r}
{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. Use limit
{pc:content action="position" posid="36" num="1" order="listorder DESC limit 1,1--" }
Use everything else as before
{pc:content action="position" posid="31" order="listorder DESC" limit='1,8--'}
{loop $data $r}
The starting position is 5, and 3 calls are made. Equivalent to the limit function.
{pc:content action="position" posid="27" order="listorder DESC" num="3" start="5"}
{loop $data $r}
{/loop}
{/pc}
13. Call keywords on the article list page, or call keywords on the homepage
注意:explode(',',$r[keywords]);是将文章关键词通过英文逗号分离,也就是说每一篇文章都要以逗号间隔关键字,否则调用出来会 是全部作为一个关键字。如果是空格间隔关键字,将explode(',',$r[keywords]);改成explode(' ',$r[keywords]);
{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}
14.每当列表几行的时候出现一次某些符号(比如首页里面的文章推荐,一行显示两条,在这两条中间想加一条竖线 | 就用到这个代码了)
数量大的话就容易出错,因为模运算嘛~~呵呵 不过一般也就4个标题以下
{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.v9 列表页完美支持自定义段调用
{pc:content action="lists" catid="$catid" num="25" order="id DESC" page="$page" moreinfo="1"}
{loop $data $r}
[{$r['字段名']}]> {$r[title]}
{/loop}
其他代码 该咋地还是要咋地 。这是要素
{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.v9 首页或分页自定义字段调用
和15差不多
第一普通列表或栏目调用自定义字段
在{pc:content action="lists" 后加上副表moreinfo=1 (等于1时显示,0时不显示)
例子:
{pc:content action="lists" moreinfo=1 catid="2" order="id DESC" num="4"}
{pc:content action="position" posid="推荐位id" num="30" thumb="1" moreinfo="1" order="listorder DESC"}
{loop $data $key $val}
20.编辑器上传图片自动使用标题作为alt参数
一: 修改 statics/js/ckeditor/plugins/image/dialogs/image.js
找到
accessKey:'T','default':''
替换成
accessKey:'T','default':$('#title').val()
二: 清除浏览器缓存
21.增加文章的随机点击数
找到100行的$views = $r['views'] +1
修改为:
$rand_nums=rand(79,186);
$views = $r['views'] + $rand_nums;
表示点击一次,增加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行改成
1. Call a single piece of data from this system, example (call the information with ID 1, the title length does not exceed 25 Chinese characters, and display the update date):
{get sql="select * from phpcms_content where contentid=1" /}
Title: {str_cut($r[title], 50)} URL: {$r[url]} Update date: {date('Y-m-d', $r[updatetime])}
2. Call multiple pieces of data from this system, example (call 10 pieces of information that have been reviewed with column ID 1, the title length does not exceed 25 Chinese characters, and the update date is displayed):
{get sql="select * from phpcms_content where catid=1 and status=99 order by updatetime desc" rows="10"}
Title: {str_cut($r[title], 50)} URL: {$r[url]} Update date: {date('Y-m-d', $r[updatetime])}
{/get}
3. With paging, example (call 10 pieces of information that have passed the review with column ID 1, title length not exceeding 25 Chinese characters, display update date, with paging):
{get sql="select * from phpcms_content where catid=1 and status=99 order by updatetime desc" rows="10" page="$page"}
Title: {str_cut($r[title], 50)} URL: {$r[url]} Update date: {date('Y-m-d', $r[updatetime])}
{/get}
Pagination: {$pages}
4. Customize the return variable, example (call the 10 pieces of information that have passed the review with the column ID 1, the title length does not exceed 25 Chinese characters, the update date is displayed, the return variable is $v):
{get sql="select * from phpcms_content where catid=1 and status=99 order by updatetime desc" rows="10" return="v"}
Title: {str_cut($v[title], 50)} URL: {$v[url]} Update date: {date('Y-m-d', $v[updatetime])}
{/get}
5. Call other databases under the same account, example (calling database is bbs, the 10 latest topics with category ID 1, the topic length does not exceed 25 Chinese characters, and the update date is displayed):
{get dbname="bbs" sql="select * from cdb_threads where fid=1 order by dateline desc" rows="10"}
Subject: {str_cut($r[subject], 50)} URL: http://bbs.phpcms.cn/viewthread.php?tid={$r[tid]} Update date: {date('Y-m-d' , $r[dateline])}
{/get}
6. Call external data, example (call the data source is bbs, the 10 latest topics with category ID 1, the topic length does not exceed 25 Chinese characters, and the update date is displayed):
{get dbsource="bbs" sql="select * from cdb_threads where fid=1 order by dateline desc" rows="10"}
Subject: {str_cut($r[subject], 50)} URL: http://bbs.phpcms.cn/viewthread.php?tid={$r[tid]} Update date: {date('Y-m-d' , $r[dateline])}
{/get}
I wonder if any friends have encountered when these methods cannot meet their needs?
For example: Take out the 3rd to 10th records with the most comments. Some people say that I am unnecessary. Generally, there is no reason not to take the first and second records with the most comments, because the thumbnails of PHPCMS are like 4:3. The size is better, but the thumbnail effect is not good for long strips (such as 3:4). In order to manually update the first and second records with the most comments, I don't want to automatically update and read the first two records.
The key point is order by B.comments desc LIMIT 3,7 (meaning starting from the 3rd record, reading 7 pieces of data downwards) This is often used in MYSQL, I had the idea of trying it, and the result It is possible.
The effect is as follows:
I hope friends who are doing PHPCMS development can learn and share together
phpcms V9 retains the usage method of get tag in 2008
It includes 2 methods, one is internal data and the other is external data
Let’s first analyze how to use internal data
1. Calling internal data
{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}
It can be seen that the get statement supports the usage of num but does not support limit 5, 5. Such usage
It’s really a pity
num is the number of calls
2. Calling external data
{ pc : get sql = "SELECT * FROM phpcms_member" cache = "3600" page = "$page" dbsource = "discuz" return = "data" }
{ loop $data $key $val }
{ $val [ username ]}< br />
{ /loop}
ul >
{ $pages }
{/ pc }
One is the data source, and the other is the generated page turning effect