EXCERPT PERSONALIZADO LA CANTIDAD DE CARACTERES


/ Published in: PHP
Save to your folder(s)

Por parámetro selecciono la cantidad de caracteres que quiero que me muestre the_excerpt() en wordpress


Copy this code and paste it in your HTML
  1. global $post;
  2.  
  3. $args = array('numberposts' => 3, 'offset'=> 0, 'order'=> 'DESC' );
  4.  
  5. $myposts = get_posts( $args );
  6.  
  7. foreach( $myposts as $post ) : setup_postdata($post);
  8. $excerpt = get_the_excerpt();
  9. add_theme_support( 'post-thumbnails' );
  10. set_post_thumbnail_size( 145, 100, true ); // Normal post thumbnails
  11. add_image_size( 'single-post-thumbnail', 400, 9999 ); // Permalink thumbnail size
  12. ?>
  13. <div class="homepostd">
  14.  
  15. <div class="thumbd">
  16. <a title="<?php the_title(); ?>" rel="bookmark" href="<?php the_permalink(); ?>">
  17. <?php
  18. if(has_post_thumbnail()) {
  19. the_post_thumbnail(array(145,100));
  20. } else {
  21. echo '<img src="'.get_bloginfo("template_url").'/images/img-default.jpg" width="150" height="64" />';
  22. }
  23. ?>
  24. </a>
  25. </div>
  26.  
  27. <div class="rightcontpd">
  28. <b><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></b>
  29. <?php echo string_limit_words($excerpt,10);?><a href="<?php the_permalink(); ?>">[...]</a>
  30. </div>
  31.  
  32. </div>
  33.  
  34. <?php endforeach; ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.