Ver Mensaje Individual
  #4 (permalink)  
Antiguo 30/03/2013, 13:08
Davi91
 
Fecha de Ingreso: noviembre-2011
Ubicación: Sevilla
Mensajes: 48
Antigüedad: 12 años, 4 meses
Puntos: 1
Respuesta: Llamar la imagen del post en el excerpt

Vale, está solucionado, aunque de aquella manera...

He utilizado una función externa, quizás haga que se cargue más lento pero de momento es la solución que tengo, así que si en un par de semanas no sale otra mejor daré el tema por solucionado!

Código PHP:
Ver original
  1. function catch_that_image() {
  2.       global $post, $posts;
  3.       $first_img = '';
  4.       ob_start();
  5.       ob_end_clean();
  6.       $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  7.       $first_img = $matches [1] [0];
  8.    
  9.       if(empty($first_img)){ //Defines a default image
  10.         $first_img = "/images/default.jpg";
  11.       }
  12.       return $first_img;
  13.     }


Código PHP:
Ver original
  1. <?php $lastposts = get_posts('category_name=Noticias&numberposts=5');foreach($lastposts as $post) : setup_postdata($post); ?>
  2.                 <li>
  3.                 <p><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></p>
  4.                 <img src="<?php echo catch_that_image() ?>" />            
  5.                 <?php excerpt('20');?><a href="<?php the_permalink(); ?>" rel="bookmark"><div id="readmore">Ver detalles</div></a>
  6.                 </li>
  7.                 <?php endforeach; ?>


Aquí el post de la solución:

http://www.wprecipes.com/how-to-get-the-first-image-from-the-post-and-display-it

Última edición por Davi91; 30/03/2013 a las 13:11 Razón: No sé que me pasa que al guardar se añade el [noparse] y no acepta el link directo, tendréis que copiar y pegar...