WordPress-Powered Portfolios: list_work() (2.9 Update)


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

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

Requires


Copy this code and paste it in your HTML
  1. <?php
  2. // http://tylersticka.com/2009/12/wp29thumbnails/
  3.  
  4. // Tell WordPress that post thumbnails are supported in this theme
  5. add_theme_support('post-thumbnails');
  6.  
  7. // Function to display a list of portfolio items, updated to support WordPress 2.9's thumbnail feature
  8. // Same arguments as get_work
  9. function list_work($exclude=null, $limit=-1, $parent=3, $args = array('orderby'=>'menu_order','order'=>'ASC','post_type'=>'page')) {
  10. // Retrieve a set of work results
  11. $work = get_work($exclude,$limit,$parent,$args);
  12. // If work is successfully retrieved, build the list
  13. if ($work) : ?>
  14. <ul>
  15. <?php
  16. // Loop through each item, making sure each has a valid post thumbnail
  17. // (So you don't break your layout)
  18. foreach ($work as $item) : if (has_post_thumbnail($item->ID)) :
  19. // Build the list item, with a linked thumbnail and title
  20. ?>
  21. <li><a href="<?php echo get_permalink($item->ID) ?>">
  22. <?php echo get_the_post_thumbnail($item->ID); ?>
  23. <?php echo apply_filters('the_title',$item->post_title); ?>
  24. </a></li>
  25. <?php endif; endforeach; ?>
  26. </ul>
  27. <?php
  28. // If no work is found, display an error message
  29. else : ?>
  30. <p>Our apologies, but we have yet to add any examples of our work. Check back soon!</p>
  31. <?php endif;
  32. }
  33. ?>

URL: http://tylersticka.com/2009/12/wp29thumbnails/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.