Show collectionParent custom attribute in page list 5.6.2.1

Permalink
Here is my issue, I have a page that contains multiple pagelist blocks showing 4 Vendors from each Vendor category. Each category has a name and an icon that I want to display above the 4 child results. The issue I have now is that the parent title and icon are also repeating...I just want to show that once, with the four child pages underneath. Here is an example of what I am trying to duplicatehttp://www.foreverbride.com/local-vendors... .

Here is my code, again I need to limit the parent category name and icon to only show once:

<div class="ccm-page-list">
  <div id="page_list_container">
    <?php  foreach ($pages as $page):
      $vendor_cat_icon = $page->getAttribute('vendor_cat_icon');
      $vendor_name = $page->getAttribute('vendor_name');
      $thumb = $ih->getThumbnail($image, 250, 9999); //width, height
      $description = $page->getCollectionDescription();
      $title = $th->entities($page->getCollectionName());
      $url = $nh->getLinkToCollection($page);
      $target = ($page->getCollectionPointerExternalLink() != '' && $page->openCollectionPointerExternalLinkInNewWindow()) ? '_blank' : $page->getAttribute('nav_target');
      $target = empty($target) ? '_self' : $target;
      $teaser = $plth->getPageTeaser($page, 'Main', $teaserBlockCount, $teaserTruncateChars);
      //$icon = $cobj->getAttribute('vendor_cat_icon');
      ?>
    <div class="col-xs-12 section_title">


If I move the "section_title" out of the foreach, it just displays home. Can someone help please? I am in a crunch and just cannot get it to click in.

Thanks!

 
hutman replied on at Permalink Best Answer Reply
hutman
You should be able to do it like this:

<?php
$pagesByParent = array();
foreach ($pages as $page){
    $pagesByParent[$page->getCollectionParentID()][] = $page;
}
?>
<div class="ccm-page-list">
    <div id="page_list_container">
        <?php foreach($pagesByParent as $parentPageID => $pages){ ?>            
            <div class="col-xs-12 section_title">
                <div class="col-xs-2 vendor_list_icon">
                    <?php 
                    $parent = page::getByID($parentPageID);
                    $parent->getAttribute('vendor_cat_icon');
                    $file = $parent->getAttribute("vendor_cat_icon");
aaronmarp replied on at Permalink Reply
Awesome, thanks HUTMAN! ;)

Worked perfectly!