codebloo

PODS CMS - Counting items within a loop

Feb 16th, 2013
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. <?php
  2.  
  3. //initialize pods
  4. $types = new Pod('press_types');
  5. $press = new Pod('press');
  6.  
  7. //Get press types sorted by id
  8. $types->findRecords('t.id',-1);
  9.  
  10. while($types->fetchRecord()){
  11. $type_slug = $types->get_field('permalink');
  12. $type_name = $types->get_field('name');
  13. $type_ID = $types->get_field('id');
  14.  
  15. ?>
  16.  
  17. <h2 id="<?php echo $type_ID; ?>" class="press_type"><?php echo $type_name; ?></h2>
  18. <ul class="group">
  19.  
  20. <?php
  21.  
  22. //Now query for all press
  23. //belonging to this press_type slug
  24. //findRecords([sort by date descending], [return all results],
  25. //[where press_type matches])
  26. $count = 1;
  27. $press->findRecords('t.date DESC', -1, 'press_type.permalink LIKE "'. $type_slug .'"');
  28.  
  29.  
  30. while($press->fetchRecord()){
  31. $press_name = $press->get_field('name');
  32. $press_date = $press->get_field('date');
  33. $project_slug = $press->get_field('permalink');
  34. ?>
  35. <li class="<?php if ($count%3 == 1) { ?> first<?php } ?>"><a href="<?php echo $get_permalink; ?><?php echo $project_slug; ?>">
  36. <div class="press-image">
  37. <?php foreach ($press->get_field('tear_sheet') as $press_photo) {
  38. $thumbnail = wp_get_attachment_image_src( $press_photo[ID], 'medium' );
  39. echo "<img src='$thumbnail[0]' class='press-img' title='$press_name'/>";}?>
  40. </div>
  41. <h3><?php echo $press_name; ?> </h3> <span class="date"><?php echo $press_date; ?></span> </a></li>
  42.  
  43. <?php
  44. }
  45. ?>
  46. <?php $count++; ?>
  47. </ul>
  48.  
  49. <?php
  50. }
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment