phpcms v9 get标签各种调用代码整理
phpcms标签调用 很多时候phpcms是我们做项目的时候用到的最好的内容发布系统了,虽然用别人的东西未免对于高手来说不耻了一些,但是能够有效的提高我们的工作效率未必也不是一件坏事
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}
不知道有没有朋友在使用中遇到这几种方法不能满足需求的时候呢?
例如:取出评论数最多的第3条到第10条记录,有人说我是多此一举,一般取最多评论没理由不取第一和第二条,因为PHPCMS的缩略图对4:3这样的尺寸比较好,对长条形(如3:4)的图片缩略效果不好,为了自己手动更新评论最多的第一和第二条记录,故此不想自动更新读取前两条。
关键点就在 order by B.comments desc LIMIT 3,7 (表示从第3条记录开始,向下读取7条数据)这个在MYSQL是经常用,我抱着试试看的想法,结果是可以的。
希望做PHPCMS开发的朋友共同学习和分享
phpcms V9 保留了2008的get标签的使用方法
它包括了2种方式一种是内部数据,另一种是外部数据
我们先分析下内部数据的使用方法
1、内部数据的调用
由此可以看出 get 语句支持num的用法但是不支持 limit 5,5.这样的用法
实在是很遗憾
num是调用的条数
2、外部数据的调用
本站资源均来自互联网或会员发布,如果不小心侵犯了您的权益请与我们联系。我们将立即删除!谢谢!