Showing Posts with custom excerpt length and custom read more text in WordPress


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



Copy this code and paste it in your HTML
  1. <?php
  2. //showing welcome post (post id =1)
  3. // retrieve one post with an ID of 5
  4. query_posts( 'p=1' );
  5. function new_excerpt_length($length) {
  6. return 28;
  7. }
  8. add_filter('excerpt_length', 'new_excerpt_length');
  9. function new_excerpt_more($more) {
  10. global $post;
  11. return '<a href="'. get_permalink($post->ID) . '"> <br />read more....</a>';
  12. }
  13. add_filter('excerpt_more', 'new_excerpt_more');
  14.  
  15. // set $more to 0 in order to only get the first part of the post
  16. global $more;
  17. $more = 0;
  18.  
  19. // the Loop
  20. while (have_posts()) : the_post();
  21. the_excerpt();
  22. endwhile;
  23. ?>

URL: http://deepakrajpal.com/?p=134

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.