Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Old Version fixes and change logs (http://forum.bytesforall.com/forumdisplay.php?f=37)
-   -   BUGFIX 364-07: Correction to how Excerpts are processed (http://forum.bytesforall.com/showthread.php?t=13607)

juggledad Apr 1, 2011 02:24 PM

BUGFIX 364-07: Correction to how Excerpts are processed
 
1 Attachment(s)
The excerpt logic was changed in 3.4.5 but a error was introduced. If there was a 'teaser' (if a '<!--more-->' is present) on the page, it would be used in place of the excerpt. The following fix changes the logic so it works in this manner

When displaying a FULL POST, break at the teaser ('<!--more-->') otherwise display the full post.

When displaying EXCERPTS
1) use a manual excerpt if it exists.
2) if a 'teaser' ('<!--more-->') shows up BEFORE the 'excerpt length' (as defined at ATO->Configure EXCERPTS->Excerpt length) is met, break the page at the <!--more-->.
3) otherwise, create a excerpt based on the ATO excerpt word count - after stripping out all HTML except the things specified in 'Don't strip these tags' - but those 'words' (a word being a string seperated by a blank) count as part of the word count. i.e. the HTML not stripped will be part of the word count.

edit functions.php and replace lines 276-325 which are
HTML Code:

// Custom Excerpts
function bfa_wp_trim_excerpt($text) { // Fakes an excerpt if needed

        global $bfa_ata, $post;

        if ( '' <> $text ) {
//  an excerpt exists, just stick on the 'custom read more' and we're done
                $words = preg_split("/\s+/", $text);
                $custom_read_more = str_replace('%permalink%', get_permalink(), $bfa_ata['custom_read_more']);
                $custom_read_more = str_replace('%title%', the_title('','',FALSE), $custom_read_more);
                array_push($words, $custom_read_more);
                $text = implode(' ', $words);
                return $text;
        }

        $text = get_the_content('');
        $words = preg_split ("/\s+/", $text);
        $post_content = $post->post_content;
        $post_content_length = count(preg_split("/\s+/", $post_content));
 
        if (count($words) < $post_content_length) {       

//  use the teaser and its 'read more'
                $bfa_ata_more_tag_final = str_replace("%post-title%", the_title('', '', false), $bfa_ata['more_tag']);
                $text = the_content($bfa_ata_more_tag_final);
                return $text;
        } else {

// Build the excerpt from the post
                $text = apply_filters('the_content', $text);
                $text = str_replace(']]>', ']]>', $text);
                $text = strip_tags($text, $bfa_ata['dont_strip_excerpts']);
                $excerpt_length = $bfa_ata['excerpt_length'];
                $words = preg_split("/\s+/", $text, $excerpt_length + 1);

// this is to handle the case where the number of words
// in the post equals the excerpt length
                if ($post_content_length >
$excerpt_length) {       
                        array_pop($words);       
                          array_pop($words);       
                        $custom_read_more = str_replace('%permalink%', get_permalink(), $bfa_ata['custom_read_more']);
                        $custom_read_more = str_replace('%title%', the_title('','',FALSE), $custom_read_more);
                        array_push($words, $custom_read_more);
                }
                $text = implode(' ', $words);
                return $text;
                }

        return $text;
}

with
HTML Code:

// Custom Excerpts
function bfa_wp_trim_excerpt($text) { // Fakes an excerpt if needed

        global $bfa_ata, $post;

        if ( '' <> $text ) {
//  an manual excerpt exists, stick on the 'custom read more' and we're done
                $words = preg_split("/\s+/", $text);
                $custom_read_more = str_replace('%permalink%', get_permalink(), $bfa_ata['custom_read_more']);
                $custom_read_more = str_replace('%title%', the_title('','',FALSE), $custom_read_more);
                array_push($words, $custom_read_more);
                $text = implode(' ', $words);
                return $text;
        }

        $text = get_the_content('');
        $words = preg_split ("/\s+/", $text);
        $post_content = $post->post_content;
        $post_content_length = count(preg_split("/\s+/", $post_content));

// Build the excerpt from the post
        $text = apply_filters('the_content', $text);
        $text = str_replace(']]>', ']]>', $text);
        $text = strip_tags($text, $bfa_ata['dont_strip_excerpts']);
        $excerpt_length = $bfa_ata['excerpt_length'];
        $words = preg_split("/\s+/", $text, $excerpt_length + 1);

// this is to handle the case where the number of words
// in the post equals the excerpt length

        if ($post_content_length > $excerpt_length) {       
                array_pop($words);       
//                  array_pop($words);       
                $custom_read_more = str_replace('%permalink%', get_permalink(), $bfa_ata['custom_read_more']);
                $custom_read_more = str_replace('%title%', the_title('','',FALSE), $custom_read_more);
                array_push($words, $custom_read_more);
        }
        $text = implode(' ', $words);
        return $text;

        return $text;
}

or you can use the following attachment which has the correction already made. This correction also has the function.php fix from BUGFIX 364-05 included
Attachment 1263


All times are GMT -6. The time now is 06:45 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.