2010-07-22 17 views

Respuesta

23

imágenes cargados se almacenan como mensajes con el tipo de "unión"; use get_posts() con los parámetros correctos. En the Codex entry for get_posts(), este ejemplo:

<?php 

$args = array(
    'post_type' => 'attachment', 
    'numberposts' => -1, 
    'post_status' => null, 
    'post_parent' => null, // any parent 
    ); 
$attachments = get_posts($args); 
if ($attachments) { 
    foreach ($attachments as $post) { 
     setup_postdata($post); 
     the_title(); 
     the_attachment_link($post->ID, false); 
     the_excerpt(); 
    } 
} 

?> 

... recorre todos los archivos adjuntos y los muestra.

Si solo desea obtener imágenes, como comentó TheDeadMedic, puede filtrar con 'post_mime_type' => 'image' en los argumentos.

+2

Sí, sólo puede usar '=> 'image'' 'post_mime_type' en su' $ args', y WordPress va a coincidir inteligentemente que contra todos los tipos MIME imagen :) – TheDeadMedic

+1

@TheDeadMedic bueno saber! Nunca he necesitado recuperar tipos particulares. –

+0

¡Buena respuesta y felicitaciones a TheDeadMedic por hacer coincidir los tipos de mimo! :) – hsatterwhite

1
<ul> 
      <?php if (have_posts()) : while (have_posts()) : the_post();  

        $args = array(
         'post_type' => 'attachment', 
         'numberposts' => -1, 
         'post_status' => null, 
         'post_parent' => $post->ID 
         ); 

        $attachments = get_posts($args); 
        if ($attachments) { 
         foreach ($attachments as $attachment) { 
          echo '<li>'; 
          echo wp_get_attachment_image($attachment->ID, 'full'); 
          echo '<p>'; 
          echo apply_filters('the_title', $attachment->post_title); 
          echo '</p></li>'; 
         } 
        } 

      endwhile; endif; ?> 
     </ul> 
+0

¿Debo crear una página nueva? – TheBlackBenzKid

Cuestiones relacionadas