Wordpress excerpt problem .. help! php code

Discussion in 'PHP' started by jasoncdu, Aug 25, 2011.

  1. #1
    Hi everyone,

    I have a site, www.utsc-isc.ca and I have a problem with the excerpt.

    If you look at the index page, there are 2 columns at the bottom: Latest ISC News and Upcoming Events.

    I have an excerpt function in place so that people can enter in the excerpt when creating either 1.) news or 2.) events, and it will show that excerpt. If there is no custom excerpt, then the first 20 words of the post shows.

    HOWEVER, I have found that many times, if I try to edit a post, after when I head back to the index page that the excerpt will disappear. Only the title remains. I have to refresh many times before the excerpt reappears. The following link is to show what I mean by the problem. Below is the code.

    http://postimage.org/image/2wqrsp8h0/

    Can anyone help me out here?

    Thanks,
    Jason

    <?php
    //'excerpt' for pages//alchymyth 2011//fix for pages with <!--nextpage--> //
    if(  $numpages >1 || end(explode('/',get_permalink($post->ID))) == end(explode('/',wp_get_referer())) ) :
     
    
    $length = 20; //set length in words
    $text = get_the_excerpt('');
        $text = apply_filters('the_excerpt', $text);
        $text = str_replace(']]>', ']]&gt;', $text);
    $text = strip_shortcodes( $text );
    $text = strip_tags($text);
    $words = explode(' ', $text, $length+1 );
      if (count($words)> $length) {
        array_pop($words);
        $text = implode(' ', $words);
      } else {
        $text = implode(' ', $words);
      }
    $text = apply_filters('the_excerpt', $text);
     
    echo $text;
     
    endif; ?>
    PHP:
     
    jasoncdu, Aug 25, 2011 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    Edit the post. Close your browser. Open another browser. (Use IE to edit, then open Firefox - something like that.) Go to the site. You should see the ecxerpt. I suspect it's a caching situation in your browser. (If I'm wrong, it cost you 60 seconds to find out.)
     
    Rukbat, Aug 25, 2011 IP
  3. jasoncdu

    jasoncdu Active Member

    Messages:
    569
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    58
    #3
    hey rukbat, you are right it is a cache problem.

    how do I make it so that it doesn't do that?

    as I have other people (not knowledgable in anything besides clicking the "add new post"), is there anyway to fix the cache problem?

    I don't see why it would cache the part where it shows none of the excerpt though?

    Thanks,
    Jason
     
    jasoncdu, Aug 25, 2011 IP