Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 26th, 2012  |  syntax: PHP  |  size: 0.88 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. // On vérifie si l'article contient une Image à la Une
  3. if( has_post_thumbnail() ) { ?>
  4.  
  5.         <div class="left">
  6.                 <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" ><?php the_post_thumbnail(); ?></a>
  7.         </div>
  8. <?php
  9. }
  10. else {
  11.         // Si l'article n'a pas d'Image à la Une, on récupère la 1ère image attachée      
  12.         $attachments = get_children(
  13.                 array(
  14.                         'post_parent'           => get_the_ID(),
  15.                         'post_type'                     => 'attachment',
  16.                         'post_mime_type'        => 'image',
  17.                         'orderby'                       => 'menu_order',
  18.                         'order'                         => 'ASC',
  19.                         'numberposts'           => 1
  20.                 )
  21.         );
  22.         if( $attachments ) {
  23.                
  24.                 foreach( $attachments as $attachment ) :
  25.                 ?>
  26.                
  27.                
  28.                 <div class="left">
  29.                         <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" ><?php echo wp_get_attachment_image($attachment->ID , 'thumbnail'); ?></a>
  30.                 </div>
  31.        
  32.        
  33.                 <?php
  34.                 endforeach;
  35.         }      
  36. }
  37. ?>