elmanisero

prima immagine nel post come thumb

Apr 1st, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.55 KB | None | 0 0
  1. <?php
  2. $attachments = get_children(array
  3. ('post_parent' => get_the_ID(),
  4.  'post_type' => 'attachment',
  5.  'post_mime_type' => 'image',
  6.  'orderby' => 'menu_order'));
  7. if ( has_post_thumbnail() ) {
  8. the_post_thumbnail( array(150,150) );
  9. } elseif ($attachments) {
  10.     if ( ! is_array($attachments) ) continue;
  11.     $count = count($attachments);
  12.     $first_attachment = array_shift($attachments);
  13.     echo wp_get_attachment_image($first_attachment->ID);
  14. } else {
  15.     echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/default.jpg" />';
  16. }
  17. ?>
Advertisement
Add Comment
Please, Sign In to add comment