Cómo controlar si un post de WordPress tiene adjuntos y mostrarlos

Saturday, October 9, 2010 18:13
Posted in category Programación, Wordpress
<?php 
 
$args = array(
  'post_type'   => 'attachment',
  'numberposts' => -1,
  'post_status' => null,
  'post_parent' => $post->ID,
  'exclude'     => null
);
 
//obtenemos los adjuntos del articulo
$attachments = get_posts($args);
if ($attachments) { //si tiene los mostramos
      foreach ($attachments as $attachment) {
             echo apply_filters('the_title', $attachment->post_title);
             the_attachment_link($attachment->ID, false);
      }
}else{  //no tiene adjuntos
?> 
<img src="images/no-pic.png"  border="0" />
<?php
}
?>
You can leave a response, or trackback from your own site.

Leave a Reply