2014-01-28 46 views
0

使用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經驗。

回答

0

如果你想顯示在你的代碼中span元素對應的頁碼:

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

如果你想顯示剩餘子頁,然後在HTML代碼段中只需更換$miescount($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); 
?> 

爲越來越長陣列有關你可以使用countsizeof。我偶然發現了一個SO question關於使用countsizeof找到數組長度的方法。

這應該讓你開始正確的方向。

+0

它顯示當前頁面中有多少頁面。我想讓它顯示下面有多少頁面。 –

0

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

這是未經測試,但理論是有道理的。

0

這可能更簡單一些。

$pl->getTotal()

$pl是在控制器設定的PageList對象。

而且,這些日子裏,你可以只使用h()方法,而不是寫出$th->entities()

編輯的:我要澄清,你不需要做$pl = new PageList(),因爲$pl已被設置爲在該PageList對象控制器並傳遞給視圖。

+0

這不起作用 - 這會獲取當前頁面列表的頁數。 OP希望'$ pl'內的每個頁面的子頁面。 –