alchymyth

page excerpt hack

Apr 17th, 2011
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1. <?php
  2. //'excerpt' for pages//alchymyth 2011//fix for pages with <!--nextpage--> //
  3. if(  $numpages >1 || end(explode('/',get_permalink($post->ID))) == end(explode('/',wp_get_referer())) ) :
  4.  
  5. the_content();
  6.  
  7. else :
  8.  
  9. $length = 120; //set length in words
  10. $text = get_the_content('');
  11.     $text = apply_filters('the_content', $text);
  12.     $text = str_replace(']]>', ']]&gt;', $text);
  13. $text = strip_shortcodes( $text );
  14. $text = strip_tags($text);
  15. $words = explode(' ', $text, $length+1 );
  16.   if (count($words)> $length) {
  17.     array_pop($words);
  18.     $text = implode(' ', $words);
  19.   } else {
  20.     $text = implode(' ', $words);
  21.   }
  22. $text = apply_filters('the_content', $text);
  23.  
  24. echo $text;
  25. echo '<a href="' . get_permalink($post->ID) . '">continue reading...</a>';
  26.  
  27. endif; ?>
Add Comment
Please, Sign In to add comment