Embed PageList w/Custom Sort

Permalink
I have created custom attributes for is_featured(checkbox) and featured_order(text, will be a number 1-6). How can I embed a PageList into a theme file that will show the is_featured pages listed in the featured_order order?

 
alcdev replied on at Permalink Reply
Ok, I have my pagelist on my page using a normal pagelist block. I am using the below custom template:
<?php
if (count($cArray) > 0) { 
   foreach($cArray as $cobj) { ?>
      <?
      $bgImage = $cobj->getCollectionAttributeValue('featured_graphic');
      $bgBanner = $cobj->getCollectionAttributeValue('featured_banner');
        if (!empty($bgImage)) {
                $fgraphic = $bgImage->getRelativePath();
                ?>
            <li style="background: #816e68">
               <img src="<?=$this->getThemePath()?>/elements/timthumb.php?src=<?=$fgraphic;?>&h=158&w=284&zc=1" alt="placeholder" class="left" />
               <p class="left" style="color:#ffffff; font-family:'GothamMedium'; font-size: 14px; text-transform: uppercase; line-height: 20px; margin: 10px 15px">
               <?=$cobj->getCollectionAttributeValue('featured_content')?>
                  <a href="<?=$nh->getLinkToCollection($cobj)?>" style="font-size:11px; text-decoration: underline; color: #fff">> VIEW DETAILS </a>
               </p>


All I need now is to somehow sort by:
$cobj->getCollectionAttributeValue('featured_order')


before running though the custom template.
Any ideas?
alcdev replied on at Permalink Reply
Any Ideas?
PatrickHeck replied on at Permalink Reply
PatrickHeck
You can sort the array by inserting this line
usort ($cArray,"myCmp");

after
if (count($cArray) > 0) {

then you need to define your sorting function at the bottom of the page like
function myCmp($a,$b) {
$fo_a = $a->getCollectionAttributeValue('featured_order');
$fo_b = $b->getCollectionAttributeValue('featured_order');
return strcasecmp($fo_a, $fo_b);
}