Advertisement
sayful

WP the_excerpt Function

Feb 20th, 2014
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.55 KB | None | 0 0
  1. /*==============================================
  2. *To Displays the post excerpt
  3. ===============================================*/
  4. <?php the_excerpt(); ?>
  5.  
  6. /*===================================================================================
  7. *Use with Conditional Tags
  8. *Replaces the_content() tag with the_excerpt() when on archive or category pages.
  9. =====================================================================================*/
  10. <?php
  11.     if ( is_category() || is_archive() ) {
  12.         the_excerpt();
  13.     } else {
  14.         the_content();
  15.     }
  16. ?>
  17.  
  18. /*======================================================================================
  19. *Control Excerpt Length using Filters
  20. *By default, excerpt length is set to 55 words.
  21. *To change excerpt length to 20 words using excerpt_length filter,
  22. add the following code to functions.php file in your theme:
  23. =======================================================================================*/
  24. <?php
  25. function custom_excerpt_length( $length ) {
  26.     return 20;
  27. }
  28. add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
  29. ?>
  30.  
  31. /*======================================================================================
  32. *Make the "read more" link to the post
  33. *Place this in a theme's functions.php to make the "read more" link to the post
  34. =======================================================================================*/
  35. <?php
  36. function new_excerpt_more( $more ) {
  37.     return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">Read More</a>';
  38. }
  39. add_filter( 'excerpt_more', 'new_excerpt_more' );
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement