Ver Mensaje Individual
  #14 (permalink)  
Antiguo 09/11/2011, 15:29
lobos1981
 
Fecha de Ingreso: abril-2011
Ubicación: Colombia
Mensajes: 59
Antigüedad: 13 años, 1 mes
Puntos: 19
Respuesta: Asignar ID a Thumbnails

Bueno Señores tengo buenas noticias... he logrado hacerlo funcionar!!

El problama ahora es q lo logré modificando media.php un archivo de núcleo de wordpress creo... y creo q no es recomendable. :(

Código PHP:
Ver original
  1. function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false, $attr = '') {
  2.     $html = '';
  3.     $image = wp_get_attachment_image_src($attachment_id, $size, $icon);
  4.     if ( $image ) {
  5.         list($src, $width, $height) = $image;
  6.         $hwstring = image_hwstring($width, $height);
  7.         if ( is_array($size) )
  8.             $size = join('x', $size);
  9.         $attachment =& get_post($attachment_id);
  10.         $numeral = '#';   [COLOR="Red"]Añadí esto[/COLOR]
  11.         $caption = $numeral . get_the_ID();  [COLOR="Red"]Añadí esto[/COLOR]
  12.         $default_attr = array(
  13.             'data-caption' => $caption,   [COLOR="Red"]y Añadí esto[/COLOR]
  14.             'src'   => $src,
  15.             'class' => "attachment-$size",
  16.             'alt'   => trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )), // Use Alt field first
  17.             'title' => trim(strip_tags( $attachment->post_title )),
  18.         );
  19.         if ( empty($default_attr['alt']) )
  20.             $default_attr['alt'] = trim(strip_tags( $attachment->post_excerpt )); // If not, Use the Caption
  21.         if ( empty($default_attr['alt']) )
  22.             $default_attr['alt'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title
  23.  
  24.         $attr = wp_parse_args($attr, $default_attr);
  25.         $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment );
  26.         $attr = array_map( 'esc_attr', $attr );
  27.         $html = rtrim("<img $hwstring");
  28.         foreach ( $attr as $name => $value ) {
  29.             $html .= " $name=" . '"' . $value . '"';
  30.         }
  31.         $html .= ' />';
  32.     }
  33.  
  34.     return $html;
  35. }
--------------------------------------

Pero seguí leyendo: y es posible hacerlo desde functions.php con los filtros, lo leí aquí:

http://www.webtechwise.com/wordpress...ages-to-posts/

Entonces creo q es mejor crear esa función en el archivo functions.php

¿Cómo sería?

Es decir crear al atributo data-caption="" dentro de la etiqueta imagen??
Y q lleve dentro de las comillas el the_ID(); del post??

Esta es la función a filtrar q tambien está en wp-includes/media.php de wordpress

Código PHP:
Ver original
  1. function get_image_tag($id, $alt, $title, $align, $size='medium') {
  2.  
  3.     list( $img_src, $width, $height ) = image_downsize($id, $size);
  4.     $hwstring = image_hwstring($width, $height);
  5.  
  6.     $class = 'align' . esc_attr($align) .' size-' . esc_attr($size) . ' wp-image-' . $id;
  7.     $class = apply_filters('get_image_tag_class', $class, $id, $align, $size);
  8.  
  9.     $html = '<img src="' . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" title="' . esc_attr($title).'" '.$hwstring.'class="'.$class.'" />';
  10.  
  11.     $html = [COLOR="Red"]apply_filters[/COLOR]( 'get_image_tag', $html, $id, $alt, $title, $align, $size );
  12.  
  13.     return $html;
  14. }

Última edición por Nekko; 10/11/2011 a las 07:16