Ver Mensaje Individual
  #6 (permalink)  
Antiguo 26/04/2011, 16:48
Avatar de j_aroche
j_aroche
Server Ninja
 
Fecha de Ingreso: agosto-2006
Ubicación: iPhone: 14.624481,-90.487457
Mensajes: 2.066
Antigüedad: 17 años, 8 meses
Puntos: 223
Respuesta: Funcion thumbnail

Si entendí bien, lo que necesitas es que the_post_thumbnail() funcione sin tener que estar indicando que imagen usar, sino que use la primera que encuentre. Yo he usado algo así:

Código PHP:
Ver original
  1. function fix_thumb($post_id){
  2.  
  3.     if ( ! has_post_thumbnail() ) {
  4.  
  5.         $args = array(
  6.             'post_type' => 'attachment',
  7.             'post_mime_type' => 'image',
  8.             'numberposts' => 1,
  9.             'post_status' => null,
  10.             'post_parent' => $post_id
  11.         );
  12.  
  13.         $attachments = get_posts($args);
  14.         foreach ($attachments as $attachment) {
  15.             set_post_thumbnail( $post_id, $attachment->ID );
  16.         }
  17.        
  18.     }
  19. }
  20.  
  21. add_filter( 'publish_post' , 'fix_thumb' , 10, 2 );
  1. Se asume que el theme ya soporta los thumbails y ya están creados; por tanto no hay "resize" y las miniaturas van a tamaño exacto.
  2. Como dije, el query es solo para que no quede sin miniatura, si no te gusta, la cambias editando el post. Si ya tiene una miniatura asignada antes de publicar el post, no hace nada.
  3. Solo funciona en WP 3.1 para arriba.
__________________
Blog: JavierAroche.com - Twitter: @j_aroche