Wordpress Themes - WP Forum at BFA
Click Here To DONATE! Support the theme development, get more attention and additional benefits based on your donation level. Your forum name will be highlighted.

Wordpress Themes - WP Forum at BFA » WordPress Themes » Atahualpa 3 Wordpress theme » Center area post/pages » Excerpts, Read more, Pagination »

Manual excerpt still cutting last word


Build custom WP THEMES, without
coding.
Click here for THEMEFRAME

From the author of Atahualpa, the #1 most
downloaded (700,000+) theme @ wordpress.org
  #1  
Old Jan 15, 2010, 04:59 PM
buzz628
 
9 posts · Jan 2010
Manual excerpt still cutting last word

I read through the posts that discussed this issue and the solution was to use the "[BUGFIX 3.4.1/3.4.2/3.4.4] Getting Configure Excerpts to work in all cases."

Since I have the newest version of Atahualpa (3.4.5.1) installed that fix has already been applied. Yet, I still have the problem where the last word in my manual excerpt does not show up for each post.

I can add a random word to the end and it will then add that last word I want but I was hoping there was a real fix somewhere.

I also have Wordpress 2.9.1 installed
  #2  
Old Jan 16, 2010, 04:15 PM
chiara7's Avatar
chiara7
 
18 posts · Sep 2009
Budapest - Hungary
I have the same problem! (With atahualpa 3.4.5.1 or 3.4.4 and WordPress 2.9.1). If I turn to Atahualpa 3.4.1, the manual excerpt is shown perfectly with all words.

Last edited by chiara7; Jan 16, 2010 at 04:18 PM.
  #3  
Old Jan 17, 2010, 12:10 PM
IanS's Avatar
IanS
 
1 posts · Jan 2010
Las Cruces, NM
I was having the same issue, and I found a slightly simpler workaround than leaving an extra word.

Just leave a space after the last word. That worked for me.
  #4  
Old Feb 6, 2010, 05:39 PM
blaise
 
2 posts · Jan 2010
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.
  #5  
Old Feb 7, 2010, 01:39 PM
chiara7's Avatar
chiara7
 
18 posts · Sep 2009
Budapest - Hungary
Wow! Thank you! It works.
  #6  
Old Feb 8, 2010, 07:35 AM
juggledad's Avatar
juggledad
 
22,244 posts · Mar 2009
OSX 10.8.5 WP 3.8.x Atahualpa 3.7.x Safari 6.x Firefox 25 XP
Blaise,

Good find! !!

When I was coding the original fix, I must have missed the manual excerpts, there are so many cases that make this a mess. I'll see if I can get Flynn to get this into the next release.
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Manual Updating to newer version - as easy as switch to new theme ? 3ukman New Versions, & Updating 3 Mar 21, 2014 07:55 PM
add manual links to the menu area izzysanime Header configuration & styling 1 Jan 11, 2010 04:50 PM
Upgrade: auto vs. manual interage New Versions, & Updating 9 Dec 28, 2009 10:53 AM
Altahualpa 3.4.1 & Manual Excerpts Issue kittydunes Excerpts, Read more, Pagination 3 Sep 10, 2009 07:09 PM
How can traslate this comments word? francos Languages & Translations 3 Apr 6, 2009 06:14 AM


All times are GMT -6. The time now is 10:46 AM.


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