WordPress.org

Ready to get started?Download WordPress

Forums

get_the_excerpt - Outside the Loop (4 posts)

  1. timjamz
    Member
    Posted 5 years ago #

    I'm trying to figure out why get_the_excerpt is delivering nothing except a line break in WP2.6. I'm echoing tags and the excerpt for meta keywords and description in my header file. I do this by setting $post as global in the header, if it's a single post, then echoing tags through a foreach, then the excerpt via get_the_excerpt.

    This works without problem in another blog I have, which is WP2.5.1. On the WP2.6 blog I'm having trouble with, echoing the tags works fine but get_the_excerpt results in only a line break. Edit: In both cases, I am not specifying an excerpt, but relying on the default 55-word filter inherent to WP.

    Was get_the_excerpt changed between 2.5.1 and 2.6? Am I missing something brilliantly simple?

    Here's my code, outside the loop, in header.php:

    To echo the excerpt:

    <?php global $post;
       if (is_single()) {
          echo strip_tags(get_the_excerpt($post->ID));
       } ?>

    To echo the tags ($post is already global):

    <?php
       if (is_single()) {
          foreach(get_the_tags($post->ID) as $tag) { echo $tag->name . ', '; }
       } ?>

    I hope this makes sense, and I appreciate any help! Thanks!

  2. timjamz
    Member
    Posted 5 years ago #

    Just a side note... even upgrading to 2.6.5, I get the same result outside the loop by making $post global. In ver.2.5.1 I am able to echo get_the_tags, get_the_excerpt, and even get_the_category. In version 2.6+, get_the_tags works just fine, but get_the_excerpt, and even get_the_category isn't working.

    I'm stumped.

  3. vanishdesign
    Member
    Posted 5 years ago #

  4. Mark
    Member
    Posted 5 years ago #

    maybe include something like

    var_dump($post);

    after you is_single() line to make sure that the $post object is actually loaded with data. If you get a NULL result then obviously it isn't. And if it is loaded then you'll see an ID element.

Topic Closed

This topic has been closed to new replies.

About this Topic