Ver Mensaje Individual
  #7 (permalink)  
Antiguo 08/11/2011, 10:33
Avatar de Nekko
Nekko
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Buenos Aires
Mensajes: 3.141
Antigüedad: 16 años, 1 mes
Puntos: 656
Respuesta: Novato Wordpress; image-attachment

Interesante, la verdad es que nunca había mirado dentro de esta función y sus aplicaciones.

Fijate probando este código, en un theme mio funcionó.

Código PHP:
Ver original
  1. function get_img_attached(){
  2. global $post;
  3. $args = array(
  4.     'post_type' => 'attachment',
  5.     'numberposts' => null,
  6.     'post_status' => null,
  7.     'post_parent' => $post->ID,
  8.     'post_mime_type' => 'image'
  9. );
  10. $attachments = get_posts($args);
  11. if ($attachments) {
  12.     foreach ($attachments as $attachment) {
  13.             $imageID = $attachment->ID;
  14.             $imageTitle = $attachment->post_title;
  15.             $imageCaption = $attachment->post_excerpt;
  16.             $imageDescription = $attachment->post_content;
  17.             $imageAlt = get_post_meta($imageID, '_wp_attachment_image_alt', true);
  18.             $imageArray = wp_get_attachment_image_src($imageID);
  19.             $imageURI = $imageArray[0];
  20.             $imageWidth = $imageArray[1];
  21.             $imageHeight = $imageArray[2];
  22.            
  23.             // Construir el marcado
  24.             $imgAtt = '<figure class="content-image><a href="' . get_permalink() . '" title="' . the_title("", "", false) . '">
  25.             <img src="' . $imageURI . ' " width="' . $imageWidth . '    " height="' . $imageHeight . '  " alt="' . $imageAlt . '" title="   ' . $imageTitle . ' " /></a><figcaption>.'. $imageCaption.' .<small><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Licencia Creative Commons Attribution Share-alike</a></small>';          
  26.             // escribir la cadena
  27.             echo $imgAtt;
  28.            
  29. }  
  30. unset($args);
  31. }
  32. }

Saludos!
__________________
Taller para crear themes wordpress desde cero | Presupuestos para trabajos particulares vía MP