DEDECMS教程之loop循环标签的使用详解
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>DedeCMS v5.7的loop标签非常有用,可以使用它来调用任意表中的数据,我们先来看看loop标签的语法结构。</p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
<pre class="brush:xhtml;">
{dede:loop table='table_name' if='condition' sort='field_name' row='line_number'}
<a href=''></a><br />
{/dede:loop}</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
上面就是loop标签的语法了,其中table_name指的是表名,也就是要查询的数据所在的表;condition是条件,相当于SQL语句中的where;field_name指的是排序方式,相当于SQL语句中的order by;line_number是行数,指要查询多少条数据,我们通过两个例子来说明loop标签的强大功能。</p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
<pre class="brush:xhtml;">
{dede:loop table='archives' sort='mid' row='4' if='mid=1'}
<a href=''></a>()<br />
{/dede:loop}</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
上面的例子是调用DedeCMS文档主表的文章,根据mid也即会员ID号排序,条件是会员ID等于1。换句话说,这段代码的作用是查询会员ID为1的用户发布的4篇文档。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
站长们也许会问为什么loop标签叫万能调用标签呢?其实它除了调用DedeCMS数据表里面的内容外,还可以调用其他程序数据表中的数据,从而起到整合数据的作用。</p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
<pre class="brush:xhtml;">
{dede:loop table='cdb_threads' if='' sort='tid' row='8'}
<a href="http://www.aspku.net/qq/">
</a><br />
{/dede:loop}</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
上述代码的功能和第一个例子类似,它用来获取Discuz! 论坛的最新主题帖子,URL标签中的域名要替换成自己的域名,各位站长可以试验下。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
总之,loop标签同时可以查询跟DedeCMS处在同一个数据库的数据表,如果您的论坛或者商城程序安装在同一数据库,也可以使用loop标签进行调用。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。</p>
頁:
[1]