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)
-   -   [SOLVED] [BUGFIX 3.4.1->3.4.6] Getting Configure Excerpts to work in all cases (http://forum.bytesforall.com/showthread.php?t=3377)

juggledad Sep 10, 2009 07:08 PM

[SOLVED] [BUGFIX 3.4.1->3.4.6] Getting Configure Excerpts to work in all cases
 
There are two ways to have excerpts using Atahualpa (1) Add an excerpt in the post (dashboard->Posts->Edit->Excerpt) or (2) have Atahualpa create one using the first X number of words in the post (ATO->Configure EXCERPTS->Excerpt length)

When you use method (2) Atahualpa will follow the excerpt with ATO->Configure EXCERPTS->Custom read more, but with option (1) it will not.

the following patch will allow the 'Custom read more' to show up in both cases.

Edit functions.php and locate the following code
in 3.4.1 it should be lines 243-266
in 3.4.2 it should be lines 250-273
HTML Code:

// Custom Excerpts
function bfa_wp_trim_excerpt($text) { // Fakes an excerpt if needed
       
        global $bfa_ata;
       
        if ( '' == $text ) {
                $text = get_the_content('');
                $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 = explode(' ', $text, $excerpt_length + 1);
                if (count($words) > $excerpt_length) {
                        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;
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'bfa_wp_trim_excerpt');

Replace that code with the following
HTML Code:

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

        if ( '' == $text ) {
                $text = get_the_content('');
                $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 = explode(' ', $text, $excerpt_length + 1);
        } else {
                $words = explode(' ', $text);
        }

        if (count($words) > $excerpt_length) {       
                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;
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'bfa_wp_trim_excerpt');


CasTex Nov 4, 2009 04:43 PM

Thanks for the fix ;).

juggledad Nov 8, 2009 05:36 PM

1 Attachment(s)
I discovered a case that wasn't covered by the previous fix. In reworking it, I've discovered a bug/feature with the standard wordpress code. It all has to do with what do you count as a word? Should HTML that is embedded in a post be part of the excerpt word count? If not, why not? What about shortcodes? If not, couldn't you argue that they just shouldn't be allowed in posts at all?

What if a post has a short code and that short code generates a bunch of text, should that text be part of the wordcount or not? it gets messy.

At any rate, what this change does is
1) use a manual excerpt if it exists.
2) if there is a 'teaser' use that
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.

This fix is for 3.4.4
1) Down load the attached file and unzip it.
2) rename your current 'functions.php', in the atahualpa folder, to 'functions_old.php'
3) copy the new 'functions.php' to your atahualpa folder
that's it


All times are GMT -6. The time now is 01:59 AM.

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