调用最新文章,带所在版块
{pc:get sql="SELECT a.title, a.catid, b.catid, b.catname, a.url as turl ,b.url as curl,a.id FROM `v9_news` a, `v9_category` b WHERE a.catid = b.catid ORDER BY `a`.`id` DESC "num="15" cache="300"}
{loop $data $r}
[{$r[catname]}] {str_cut($r['title'],26)}
{/loop}
{/pc}
截取调用标题的长度
{str_cut($v['title'],34)} -----超出用 ... 代替
{str_cut($v['title'],34, '???')}-----超出用 ???代替
{str_cut($v['title'],34,'')}-----超出不用任何字符代替
格式化时间调用
{date('Y-m-d H:i:s',$r[inputtime])}-----2013-07-25:11:22:33
{date('m-d',$v['inputtime'])}------07-25
多栏目调用&多推荐位调用调用需求:文章范围为59 60 61三个栏目,并且推送到了27 和28两个推荐位;从第三条开始,连续调用7篇文章。
{pc:get sql="SELECT * FROM v9_news WHERE id IN (SELECT id FROM v9_position_data WHERE posidin(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}
调用子栏目(在栏目首页模板需要用到)
{pc:content action="category" catid="$catid" num="25" siteid="$siteid" order="listorderASC"}
{loop $data $r}
{$r[catname]} |
{/loop}
{/pc}
获取固定栏目信息
{pc:get sql="SELECT * FROM phpcms_category where parentid = 0 and catid > 5" return="data"}
<?php var_dump($data)?>
{/pc}
获取三级分类信息
{pc:content action="category" catid="$top_parentid" num="15" siteid="$siteid" order="listorder ASC"}
{loop $data $r}
<a href="{$r[url]}">{$r[catname]}</a><span> | </span>
{loop subcat($r['catid']) $c2}
二级分类: <a href="{$c2['url']}">{$c2['catname']}</a><span> | </span>
{loop subcat($c2['catid']) $c3}
三级分类: <a href="{$c3['url']}">{$c3['catname']}</a><span> | </span>
{/loop}
{/loop}
{/loop}
{/pc}
显示指定id的栏目名称
{$CATEGORYS[22]['catname']}
编辑器上传图片自动使用标题作为alt参数
一: 修改 statics/js/ckeditor/plugins/image/dialogs/image.js找到accessKey:'T','default':''
替换成accessKey:'T','default'('#title').val()
二: 清除浏览器缓存
在文章面前显示文章类别;
{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}
文章调用使用limit;
{pc:content action="position" posid="31" order="listorder DESC" limit='1,8--'}
{loop $data $r}
{str_cut($r[title],36,'')}
{/loop}
{/pc}
文章从指定位置开始调用起始位置为5,调用3条;
{pc:content action="position" posid="27" order="listorder DESC" num="3" start="5"}
{loop $data $r}
{str_cut($r[description],115)}...
{/loop}
{/pc}
文章列表页调用关键字,或者首页调用关键字注意: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}
每当列表几行的时候出现一次某些符号(比如首页里面的文章推荐,一行显示两条,在这两条中间想加一条竖线 | 就用到这个代码了)数量大的话就容易出错,因为模运算嘛~~呵呵 不过一般也就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}
v9 列表页完美支持自定义段调用;
{pc:content action="lists" catid="$catid" num="25" order="id DESC" page="$page"moreinfo="1"}
{loop $data $r}
[{$r['字段名']}]> {$r[title]}
{/loop}
{$pages}
{/pc}
当前栏目调用父级及以下栏目信息方法其他代码;
{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"}
V9表单功能 提交之后如何返回当前页面,而不是默认的首页文件地址;
找到 phpcms\modules\formguide\index.php文件第73行
showmessage(L('thanks'), APP_PATH);
修改成 如下代码即可实现自动返回前一页
showmessage(L('thanks'), HTTP_REFERER);
增加文章的随机点击数
找到100行的$views = $r['views'] +1修改为:
$rand_nums=rand(79,186);
$views = $r['views'] + $rand_nums;
表示点击一次,增加79到186次不等
PHPCMS V9的get标签调用;
-
调用本系统单条数据,示例(调用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])} -
调用本系统多条数据,示例(调用栏目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} -
带分页,示例(调用栏目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}
{$CATEGORYS[$catid][description]}显示栏目描述
{catpos($catid)} 显示文章位置导航
{$CATEGORYS[$catid][url]} 显示当前栏目链接
{$CATEGORYS[$catid][catname]} 显示当前栏目名称
phpcms v9通过引用$CATEGORYS变量缓存,就可以单独调用栏目属性字段,方法如下
在需要调用栏目属性字段的地方,插入:
{$CATEGORYS = getcache('category_content_'.$siteid,'commons'); }
1
或者还可以加一个if判断:
<?php if(!isset($CATEGORYS)) { $CATEGORYS = getcache('category_content_'.$siteid,'commons'); } ?>
1
这样,就把缓存文件caches/caches_commons/caches_data/category_content_1.cache.php引用了,之后就可以任意调用数据了:
当前栏目id: {$catid}
当前栏目名: {$CATEGORYS[$catid][catname]}
当前栏目目录名: {$CATEGORYS[$catid][catdir]}
当前栏目url: {$CATEGORYS[$catid][url]}
当前栏目位置(面包屑导航): 首页 > {catpos($catid)} 正文
当前栏目描述: {$CATEGORYS[$catid][description]}
当前栏目图片: {$CATEGORYS[$catid][image]}
当前栏目的内容数: {$CATEGORYS[$catid][items]}
当前栏目的点击数: {$CATEGORYS[$catid][hits]}
其中$catid表示当前栏目ID,也可以直接指定固定的数字调用。
Come on…
公众号:极客仿
本文详细介绍了PHPCMS的代码调用方法,包括最新文章调用、标题长度截取、时间格式化、多栏目及推荐位调用、子栏目获取、固定栏目和三级分类信息、文章类别显示、关键字调用、自定义段调用等,适用于PHPCMS V9系统的开发和优化。

293

被折叠的 条评论
为什么被折叠?



