PHP和混凝土5计数子页面
使用Concrete5制作移动网站并使用自定义模板的页面列表块。我试图用PHP计算子页面。PHP和混凝土5计数子页面
<?php foreach ($pages as $page):
// Prepare data for each page being listed...
$title = $th->entities($page->getCollectionName());
$url = $nh->getLinkToCollection($page);
$target = ($page->getCollectionPointerExternalLink() != '' && $page->openCollectionPointerExternalLinkInNewWindow()) ? '_blank' : $page->getAttribute('nav_target');
$target = empty($target) ? '_self' : $target;
$description = $page->getCollectionDescription();
$description = $controller->truncateSummaries ? $th->shorten($description, $controller->truncateChars) : $description;
$description = $th->entities($description);
$mies = 0;
?>
<li class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-btn-up-c" data-theme="c"><div aria-hidden="true" class="ui-btn-inner ui-li"><div class="ui-btn-text"><a target="<?php echo $target ?>" class="ui-link-inherit" href="<?php echo $url ?>">
<h2 class="ui-li-heading"><?php echo $title ?></h2>
<p class="ui-li-desc"><?php echo $description ?></p>
</a>
</div><span class="ui-icon ui-icon-arrow-r ui-icon-shadow"></span><span class="ul-li-count ui-btn-corner-all ul-count-second"><?php echo count($mies) ?></span></div></li>
<?php endforeach; ?>
所以,可能需要使用Count函数(或长度?),我不知道。如果我在编辑错误的地方,请咨询你是否有任何Concrete5 cms经验。
如果你想显示在你的代码中span
元素对应的页码:
<span class="ul-li-count ui-btn-corner-all ul-count-second"><?php echo $mies; ?></span>
如果你想显示剩余子页,然后在HTML代码段中只需更换$mies
与count($pages) - $mies
,如:
<span class="ul-li-count ui-btn-corner-all ul-count-second"><?php echo count($pages) -$mies; ?></span>
您必须先初始化$mies
启动for
循环之前,所以它应该是这样的形式的东西:
<?php
$mies = 0;
foreach ($pages as $page):
//Rest of your code and increment $mies with every iteration
$mies ++; //This ensures that you are counting the corresponding pages
?>
如果你想获得的子页面总数的计数,你只需要回声出$mies
外块可能是这样的:据
<?php
endforeach;
echo $mies; //Shows you the total number of pages processed inside the for loop.
//or Just find the length of pages array
echo count($pages);
?>
为越来越长阵列有关你可以使用count
或sizeof
。我偶然发现了一个SO question关于使用count
或sizeof
找到数组长度的方法。
这应该让你开始正确的方向。
您需要父母ID;
$parentId = Page::getCollectionParentId();
注意Page::getCollectionParentId()
获取当前页的父ID,所以你可能想尝试;
$parentId = $page->getCollectionParentID();
然后创建一个新的PageList来过滤和由parentId过滤;
Loader::model('page_list');
$pl = new PageList();
$pl->filter(false, '(p1.cParentID IN ' . $parentId . ')');
// Get the total
var_dump($pl->getTotal());
这是未经测试,但理论是有道理的。
这可能更简单一些。
$pl->getTotal()
$pl
是在控制器设定的PageList
对象。
而且,这些日子里,你可以只使用h()
方法,而不是写出$th->entities()
编辑的:我要澄清,你不需要做$pl = new PageList()
,因为$pl
已被设置为在该PageList
对象控制器并传递给视图。
这不起作用 - 这会获取当前页面列表的页数。 OP希望'$ pl'内的每个页面的子页面。 –
它显示当前页面中有多少页面。我想让它显示下面有多少页面。 –