PHPCMS快速建站系列之标签循环嵌套

标签循环嵌套方法,可以实现对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}
posted @ 2017-01-20 18:11  MY0101  阅读(1027)  评论(0编辑  收藏  举报