【问题标题】:PHP and Concrete 5 count subpagesPHP 和 Concrete 5 计算子页面
【发布时间】:2014-01-28 07:16:38
【问题描述】:

使用 Concrete5 制作移动网站并使用带有自定义模板的页面列表块。我正在尝试使用 PHP 计算子页面。

<?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; ?>

所以,可能需要使用计数函数(或长度?),我不知道。如果我编辑错误的地方,如果您有任何 Concrete5 cms 经验,请提出建议。

【问题讨论】:

    标签: php concrete5


    【解决方案1】:

    如果您想在代码中的span 元素中显示相应的页码:

    <span class="ul-li-count ui-btn-corner-all ul-count-second"><?php echo $mies; ?></span>
    

    如果要显示剩余的子页面,那么在上面的html代码sn-p中只需将$mies替换为count($pages) - $mies就好:

    <span class="ul-li-count ui-btn-corner-all ul-count-second"><?php echo count($pages) -$mies; ?></span>
    

    在启动 forloop 之前,您首先必须初始化 $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
    
    ?>
    

    如果你想得到子页面的总数,你只需要在for块之外回显$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);
    ?>
    

    就获取数组的长度而言,您可以使用countsizeof。我偶然发现了 SO question 关于使用 countsizeof 查找数组长度的方法。

    这应该会让你朝着正确的方向开始。

    【讨论】:

    • 显示当前页有多少页。我想让它显示它下面有多少页。
    【解决方案2】:

    您需要父 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());
    

    这是未经测试的,但理论是有道理的。

    【讨论】:

      【解决方案3】:

      这可能有点简单。

      $pl-&gt;getTotal()

      $pl 是控制器中设置的PageList 对象。

      另外,现在你可以只使用h() 方法而不是写出$th-&gt;entities()

      编辑:我应该澄清您不需要执行$pl = new PageList(),因为$pl 已经设置为控制器中的PageList 对象并传递给视图。

      【讨论】:

      • 这不起作用 - 这将获取当前页面列表的页数。 OP 想要 $pl 中每个页面的子页面。
      猜你喜欢
      • 2016-10-14
      • 1970-01-01
      • 1970-01-01
      • 2012-05-28
      • 1970-01-01
      • 1970-01-01
      • 2011-12-10
      • 1970-01-01
      • 2018-12-05
      相关资源
      最近更新 更多