[wp-trac] [WordPress Trac] #28278: Smart Excerpt

WordPress Trac noreply at wordpress.org
Sun May 25 05:04:46 UTC 2014


#28278: Smart Excerpt
-------------------------------+------------------------------
 Reporter:  GreatBlakes        |       Owner:
     Type:  enhancement        |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Posts, Post Types  |     Version:  3.9.1
 Severity:  normal             |  Resolution:
 Keywords:                     |     Focuses:
-------------------------------+------------------------------

Comment (by GreatBlakes):

 I've recently made some pretty heavy adjustments to enhance this function:

 {{{
 //Several ways to implement this:
         //Inside the loop (or outside the loop for current post/page):
 nebula_the_excerpt('Read more »', 20, 1);
         //Outside the loop: nebula_the_excerpt(572, 'Read more »',
 20, 1);
 function nebula_the_excerpt( $postID=0, $more=0, $length=55, $hellip=0 ) {

         if ( $postID && is_int($postID) ) {
                 $the_post = get_post($postID);
         } else {
                 if ( $postID != 0 || is_string($postID) ) {
                         if ( $length == 0 || $length == 1 ) {
                                 $hellip = $length;
                         } else {
                                 $hellip = false;
                         }

                         if ( is_int($more) ) {
                                 $length = $more;
                         } else {
                                 $length = 55;
                         }

                         $more = $postID;
                 }
                 $postID = get_the_ID();
                 $the_post = get_post($postID);
         }

         if ( $the_post->post_excerpt ) {
                 $string =
 strip_tags(strip_shortcodes($the_post->post_excerpt), '');
         } else {
                 $string =
 strip_tags(strip_shortcodes($the_post->post_content), '');
         }

         $string = string_limit_words($string, $length); //Note that this
 function is just a string limiter. I can post the code if needed.

         if ( $hellip ) {
                 if ( $string[1] == 1 ) {
                         $string[0] .= '… ';
                 }
         }

         if ( isset($more) && $more != '' ) {
                 $string[0] .= ' <a class="nebula_the_excerpt" href="' .
 get_permalink($postID) . '">' . $more . '</a>';
         }

         return $string[0];
 }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28278#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list