Ver Mensaje Individual
  #8 (permalink)  
Antiguo 16/01/2013, 19:30
Avatar de zanguanga
zanguanga
Moderadora
 
Fecha de Ingreso: julio-2009
Ubicación: España
Mensajes: 1.686
Antigüedad: 14 años, 9 meses
Puntos: 429
Respuesta: En volcado de posts por cat muestre la 1a foto de cada uno

Entre que la página del plugin viene en árabe y que nunca lo he usado me estoy perdiendo.

Acabo de rescatar un código que yo usé y funcionaba. Te lo paso por si quieres probar.

en functions.php:

Código PHP:
Ver original
  1. //no tener que elegir miniatura
  2. function vp_get_thumb_url($text) {
  3.     global $post;
  4.     $imageurl="";        
  5.  
  6.     // extract the thumbnail from attached imaged
  7.     $allimages =&get_children('post_type=attachment&post_mime_type=image&post_parent=' . $post->ID );        
  8.  
  9.     foreach ($allimages as $img) {                
  10.         $img_src = wp_get_attachment_image_src($img->ID);
  11.         break;                      
  12.         }
  13.  
  14.     $imageurl=$img_src[0];
  15.  
  16.     // try to get any image
  17.     if (!$imageurl) {
  18.     preg_match('/<\s*img [^\>]*src\s*=\s*[\""\']?([^\""\'>]*)/i' ,  $text, $matches);
  19.     $imageurl=$matches[1];
  20.     }
  21.  
  22.     // try to get youtube video thumbnail
  23.     if (!$imageurl) {
  24.     preg_match("/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/watch(\?v\=|\/v\/)([a-zA-Z0-9\-\_]{11})([^<\s]*)/", $text, $matches2);
  25.  
  26.     $youtubeurl = $matches2[0];
  27.     if ($youtubeurl)
  28.     $imageurl = "http://i.ytimg.com/vi/{$matches2[3]}/1.jpg";
  29.     else preg_match("/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/(v\/)([a-zA-Z0-9\-\_]{11})([^<\s]*)/", $text, $matches2);
  30.  
  31.     $youtubeurl = $matches2[0];
  32.     if ($youtubeurl)
  33.     $imageurl = "http://i.ytimg.com/vi/{$matches2[3]}/1.jpg";
  34.     }
  35.  
  36.     return $imageurl;
  37. }

En la plantilla category.php o en la que uses para volcar el post:

Código PHP:
Ver original
  1. <?php {  // este codigo corresponde a la funcion no tener que elegir miniatura en archivo functions.php
  2.             global $post;
  3.             $thumb=vp_get_thumb_url($post->post_content);
  4.             if ($thumb!='') echo '<img class="attachment-thumbnail" src="'.$thumb.'" alt="'. get_the_title().'" />';
  5.             } ?>
__________________
Mi blog personal | Mi G+