PHP和混凝土5计数子页面
使用Concrete5制作移动站点,并使用带有自定义模板的页面列表块。我正在尝试使用PHP计算子页面PHP和混凝土5计数子页面,php,concrete5,Php,Concrete5,使用Concrete5制作移动站点,并使用带有自定义模板的页面列表块。我正在尝试使用PHP计算子页面 <?php foreach ($pages as $page): // Prepare data for each page being listed... $title = $th->entities($page->getCollectionName()); $url = $nh->getLinkToCollection($page); $target = ($pa
<?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; ?>
所以,可能需要使用计数函数(或长度?),我不知道。如果我编辑错误的地方,请告知您是否有Concrete 5 cms方面的经验。如果您想在代码中的
span
元素中显示相应的页码:
<span class="ul-li-count ui-btn-corner-all ul-count-second"><?php echo $mies; ?></span>
在启动for
循环之前,首先必须初始化$mies
,因此它应该是以下形式:
<?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
?>
就获取数组长度而言,您可以使用count
或sizeof
。我偶然发现了一个关于使用count
或sizeof
方法来查找数组长度的方法
这会让您从正确的方向开始。您需要父ID
$parentId = Page::getCollectionParentId();
请注意,Page::getCollectionParentId()
获取当前页面的父ID,因此您可能需要尝试
$parentId = $page->getCollectionParentID();
然后创建一个新的页面列表进行过滤,并按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
是在控制器中设置的页面列表
对象
此外,现在您可以只使用h()
方法,而不用写出$th->entities()
编辑:我应该澄清,您不需要执行
$pl=new PageList()
,因为$pl
已设置为控制器中的PageList
对象并传递给视图。它显示当前页面中的页面数。我想让它显示它下面有多少页。这不起作用-这会获取当前页列表的页数。OP需要$pl
中每个页面的子页面。
$parentId = $page->getCollectionParentID();
Loader::model('page_list');
$pl = new PageList();
$pl->filter(false, '(p1.cParentID IN ' . $parentId . ')');
// Get the total
var_dump($pl->getTotal());