• Hi Guys,

    I’ve customized my template in this fashion:

    My pages only show my excerpt.
    Clicking a ‘read more’ link switches to that entry’s page and shows the entire post.

    Now I want to take it a step further.

    Some of my entries are short and typing an excerpt for them is stupid. I’d like something like the following:

    If there is an excerpt, display it with the ‘read more’ link (this part is done).

    If there is no excerpt, display the entire post. (This is the new bit).

    Is there some quick and dirty way to do this without querying the database to see if each entry has an excerpt associated with it in the database or not?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter heatsink

    (@heatsink)

    Hmm..I didn’t explain that very well.

    Current situation:

    <?php if ( !is_single() && ! is_page()) { ?>
    <?php the_excerpt();?>
    <?php if (!is_page()) {?>
    “>[read it!]
    <?php } } ?>

    Desired situation:

    <?php if ( !is_single() && ! is_page()) { ?>
    IF POST HAS AN EXCERPT {
    <?php the_excerpt();?>
    <?php if (!is_page()) {?>
    “>[read it!]
    }
    ELSE {
    DISPLAY THE ENTIRE POST
    }
    <?php } } ?>

    Ugly, but you get the idea, I hope. It’s the bits in CAPS that I can’t figure out.

    And no, I’m not a coder. Can you tell? 🙂

    This might work, but I’m not sure:
    <?php
    if ($post->excerpt == '') {
    the_content();
    }else {
    the_excerpt();
    }
    ?>

    It checks the excerpt field, if it’s empty, then it’ll display the content, otherwise it’ll display the excerpt itself.

    -tg

    Thread Starter heatsink

    (@heatsink)

    Thanks for the code, I see what you’re going for, but the IF always evaluates to the content.

    The full content is being displayed regardless of the presence or absence of an excerpt and the excerpt is never being displayed.

    What does an empty excerpt look like? Perhaps ” isn’t the right value?

    Best way to do this… find the functions-post.php file (it’s in the wp-includes folder). Open it up and look for the_excerpt. Look to see how it does the check, and just mimic that.

    -tg

    Thread Starter heatsink

    (@heatsink)

    That helped, thanks! Here’s what I ended up with”

    ‘<!– Check what to display – excerpt or content–>
    <?php
    if (empty($post->post_excerpt)) {
    the_content();
    }else {
    the_excerpt();?>
    “>[read the rest…]
    <?
    }
    ?>
    <!– check –>

    Can you tell me which file you are editing with this code? It is a solution I am looking for, but not sure which file to edit.

    Thanks

    i would use the same system in my blog…how can i modify the loop code in the archive ?

    <?php while (have_posts()) : the_post(); ?>

    <?php the_content('Read on &raquo;'); ?>

    <h2 class="storytitle" id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>

    <div class="date">Published on <?php the_time('l') ?>, <?php the_time('F') ?> <?php the_time('jS') ?>, <?php the_time('Y') ?> | <?php comments_popup_link(__('No Comments'), __('1 Comment'), __('% Comments')); ?> <?php wp_link_pages(); ?> <?php edit_post_link('Edit'); ?> </div>

    <!--
    <?php trackback_rdf(); ?>
    -->

    <?php endwhile; else: ?>
    <h2>Not Found</h2>
    <p><?php _e("Sorry, but you are looking for something that isn't here."); ?></p>
    <?php endif; ?>

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Show Full Post if There is No Excerpt.’ is closed to new replies.