In fact, this problem occurs because of some inconsistent logic in the same function that's mentioned in "[BUGFIX 3.4.1/3.4.2/3.4.4] Getting Configure Excerpts to work in all cases."
When faking an excerpt from content, the function
bfa_wp_trim_excerpt cleverly counts the words in the article and, if the wordcount is over the limit, removes the excess words and adds the "read more" link.
This almost works, almost by accident, when using real excerpts, because the limit looks like zero, so the "read more" link always gets added, which is what we want. Unfortunately, since the function "thinks" the excerpt has excess text, it also removes the last word, unless the article ends in a space.
A quick fix is to make the conditions explicit. In functions.php in the Atahualpa theme directory, replace
Code:
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;
}
by
Code:
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);
$faked_excerpt = true; // Drop excess words in a faked excerpt (see below)
} else {
$words = explode(' ', $text);
$excerpt_length = 0; // Force the readmore link when using a real excerpt
$faked_excerpt = false; // Do NOT drop the last word of a real excerpt (see below)
}
if (count($words) > $excerpt_length) {
if($faked_excerpt) array_pop($words); // Drop excess words ONLY IF EXCERPT IS FAKED
$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;
}
All the added/changed lines have comments. If you don't understand the code, look at the documentation of the limit option for the php function
explode.
I didn't want to tweak the code too much... However, it
would be cleaner to separate the two cases. Pseudo code:
Code:
If there IS a real excerpt (
Set the "show read more" flag
)
If there is NO real excerpt (
If there are more than max-length words (
Remove the excess words
Set the "show read more" flag
)
If less than max-length words (
Do NOT set the "show read more" flag
)
)
If the "show read more" flag is set (
Generate and add the "read more" text
)
This approach would also save a -- probably insignificant -- amount of execution time when using real excerpts and when the article is shorter than the limit.
Hope this helps.