WordPress-Powered Portfolios: list_work()


/ Published in: PHP
Save to your folder(s)

For use in conjunction with the get_work function in the theme functions template, functions.php.


Copy this code and paste it in your HTML
  1. <?php
  2. // http://tylersticka.com/2009/09/wcpdx09/
  3. // Function to display a list of portfolio items
  4. // Same arguments as get_work
  5. function list_work($exclude=null, $limit=-1, $parent=3, $args = array('orderby'=>'menu_order','order'=>'ASC','post_type'=>'page')) {
  6. // Retrieve a set of work results
  7. $work = get_work($exclude,$limit,$parent,$args);
  8. // If work is successfully retrieved, build the list
  9. if ($work) : ?>
  10. <ul>
  11. <?php
  12. // Loop through each item
  13. foreach ($work as $item) :
  14. // Grab the item's custom meta
  15. $fields = get_post_custom($item->ID);
  16. // Build the list item, with a linked thumbnail and title
  17. ?>
  18. <li><a href="<?php echo get_permalink($item->ID) ?>">
  19. <img src="<?php echo $fields['tn'][0] ?>" alt="" />
  20. <?php echo apply_filters('the_title',$item->post_title); ?>
  21. </a></li>
  22. <?php endforeach; ?>
  23. </ul>
  24. <?php
  25. // If no work is found, display an error message
  26. else : ?>
  27. <p>Our apologies, but we have yet to add any examples of our work. Check back soon!</p>
  28. <?php endif;
  29. }
  30. ?>

URL: http://tylersticka.com/2009/09/wcpdx09/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.