Ver Mensaje Individual
  #3 (permalink)  
Antiguo 12/10/2010, 18:00
Dinvaders
 
Fecha de Ingreso: octubre-2010
Ubicación: Uruguay
Mensajes: 12
Antigüedad: 13 años, 6 meses
Puntos: 0
Respuesta: Estilo de la nota completa diferente al index

Si quieres que te salga solamente el titulo de la noticia y la imagen en el index, debes hacer varias cosas:

En el archivo functions.php debes colocar este código:

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

Con esto ya puesto en functions.php nos dirigiremos a nuestro index.php donde suplantaremos el código normal por este:

Código PHP:
Ver original
  1. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  2.  
  3. <div id="post">
  4. <img src="<?php echo catch_that_image();?>" alt="<?php the_title();?>" />
  5. <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
  6. </div>
  7.  
  8. <?php endwhile; else: ?>
  9. <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
  10. <?php endif; ?>

Saludos