phpcms如何嵌套循环

时间:2022-12-15 00:03:48

PHPCMS V9的标签制作以灵活见长,可以*DIY出个性的数据调用,对于制作有风格有创意的网站模板很好用,今天就介绍一个标签循环嵌套方法,可以实现对PC标签循环调用,代码如下:

在此文件里/phpcms/lib/classes/template_cache.class.php 里的 template_parse 方法里,添加如下代码:

$str = preg_replace ("/\{loop(\S+)\s+(\S+)\s+(\S+)\}/","<?php \$n\\1=1;if(is_array(\\2)) foreach(\\2 AS \\3) { ?>", $str );
$str = preg_replace ("/\{loop(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\}/","<?php \$n\\1=1; if(is_array(\\2)) foreach(\\2 AS \\3 => \\4) { ?>", $str );
$str = preg_replace ("/\{\/loop(\S+)\}/","<?php \$n\\1++;}unset(\$n\\1); ?>", $str );
{pc:content action="category" catid="0" num="60" order="listorder ASC"}
{loop $data $r}
<dd> <a href="{$r[url]}">{$r[catname]}</a>
<ul>
{pc:content action="category" catid="$r['catid']" num="60" order="listorder ASC" return="data2"}
{loop2 $data2 $v}
<li><a href="{$v[url]}">{$v[catname]}</a></li>
{/loop2}
{/pc}
</ul>
</dd>
{/loop}
{/pc}