Ver Mensaje Individual
  #6 (permalink)  
Antiguo 04/04/2013, 04:22
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: Llamar la imagen del post en el excerpt

Generalmente hay que marcar la imagen como destacada para que sea utilizada en the_post_thumbnail. Podés hacer que se añada automáticamente la primera que encuentre con este código:

Código PHP:
Ver original
  1. function auto_post_thumbnail() {
  2.           global $post;
  3.           $already_has_thumb = has_post_thumbnail($post->ID);
  4.               if (!$already_has_thumb)  {
  5.               $attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
  6.                           if ($attached_image) {
  7.                                 foreach ($attached_image as $attachment_id => $attachment) {
  8.                                 set_post_thumbnail($post->ID, $attachment_id);
  9.                                 }
  10.                            } else {
  11.                                 set_post_thumbnail($post->ID, 'ID_imagen_por_defecto');
  12.                            }
  13.                         }
  14.       }
  15.  //Final de la función
  16. add_action('the_post', 'auto_post_thumbnail');
  17. add_action('save_post', 'auto_post_thumbnail');
  18. add_action('draft_to_publish', 'auto_post_thumbnail');
  19. add_action('new_to_publish', 'auto_post_thumbnail');
  20. add_action('pending_to_publish', 'auto_post_thumbnail');
  21. add_action('future_to_publish', 'auto_post_thumbnail');
__________________
Taller para crear themes wordpress desde cero | Presupuestos para trabajos particulares vía MP