Reading Page Attributes in Page List

Permalink
I have a quite complicated (I think) Question:

I have various sites (say: "b", "c" and "d") under a certain site in my sitemap (say "a"), that are all listed via page list (so "b", "c" and "d" are all listed via page list on "a"). the pages all have a certain image page attribute.

is it possible to read out these image attributes and have them somehow shown in my page list? i know I can read out the image attribute of the page i am on right now (f.e. like this: "<?php echo($c->getAttribute('bckimage')->getVersion()->getRelativePath());?>" - but is it possible, to read out image attributes of sites that are just linked to via page list?

 
bbeng89 replied on at Permalink Reply
bbeng89
Sure! First you need to make a custom template for the page list that will include the images. This is important because you don't want to modify the core code because your changes will be erased in an update. This link will walk you through creating a custom template:http://www.concrete5.org/documentation/how-tos/designers/custom-blo...

In your custom template, you'll have a loop that goes through each of the pages in the page list. In that loop you just need to pull each page's value for the image attribute then display it on the page. Here is some code that shows you how:
<?php $ih = Loader::helper('image'); ?>
<?php  foreach ($pages as $page):
      //get the image attribute for the current page in the loop
      $img = $page->getAttribute('img_attr_handle');
      //create a thumbnail of the image - replace 64 with max width and 9999 with max height
      $thumb = $ih->getThumbnail($img, 64, 9999, false);
      ?>
      <img src="<?php  echo $thumb->src ?>" width="<?php  echo $thumb->width ?>" height="<?php  echo $thumb->height ?>" alt="" />
<?php  endforeach; ?>


Hope that helps!

Blake