Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Right now my excerpts are doubling when I use post formats. I would like to have a default excerpt when no post format is selected. Checkout an example: http://themeforward.com/demo2/

For my excerpts, to call post formats I am using this code:

<?php
if ( has_post_format( 'aside' )) {
    ?>
    <span class="icon-aside"></span>
    <a href="<?php the_permalink() ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
    </a>
    <span class="sub-title">Posted <?php the_time("F j, Y"); ?> by <?php the_author_posts_link(); ?> in <?php the_category(', ') ?></span>
    <span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
    <?php the_excerpt();
}
if ( has_post_format( 'chat' )) {
    ?>
    <span class="icon-chat"></span>
    <a href="<?php the_permalink() ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
    </a>
    <span class="sub-title"><?php the_time("F j, Y"); ?> &nbsp;/&nbsp; <?php the_author_posts_link(); ?> &nbsp;/&nbsp; <?php the_category(', ') ?></span>
    <span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
    <?php the_excerpt();
}
if ( has_post_format( 'gallery' )) {
    ?>
    <span class="icon-gallery"></span>
    <a href="<?php the_permalink() ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
    </a>
    <span class="sub-title">
    <?php the_author_posts_link(); ?> &nbsp;/&nbsp; <?php the_category(', ') ?> &nbsp;/&nbsp; <?php the_time("F j, Y"); ?>
    </span>
    <span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
    <?php the_content(); ?>
    <?php comments_number( 'no responses', 'one response', '% responses' );
}
if ( has_post_format( 'image' )) {
    ?>
    <span class="icon-image"></span>
    <a href="<?php the_permalink() ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
    </a>
    <span class="sub-title"><?php the_time("F j, Y"); ?> &nbsp;/&nbsp; <?php the_author_posts_link(); ?> &nbsp;/&nbsp; <?php the_category(', ') ?></span>
    <span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
    <?php the_excerpt();
}
if ( has_post_format( 'link' )) {
    ?>
    <span class="icon-link"></span>
    <h1><a href="<?php  echo $first_link = catch_that_link(); ?>"><?php the_title(); ?></a></h1>
    <a href="<?php the_permalink() ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
    </a>
    <span class="sub-title"><?php the_time("F j, Y"); ?> &nbsp;/&nbsp; <?php the_author_posts_link(); ?> &nbsp;/&nbsp; <?php the_category(', ') ?></span>
    <?php comments_number( 'no responses', 'one response', '% responses' );
}
if ( has_post_format( 'quote' )) {
    ?>
    <span class="icon-quote"></span>
    <a href="<?php the_permalink() ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
    </a>
    <span class="sub-title"><?php the_time("F j, Y"); ?> &nbsp;/&nbsp; <?php the_author_posts_link(); ?> &nbsp;/&nbsp; <?php the_category(', ') ?></span>
    <span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
    <?php the_content();
}
if ( has_post_format( 'status' )) {
    ?>
    <span class="icon-status"></span>
    <a href="<?php the_permalink() ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
    </a>
    <span class="sub-title"><?php the_time("F j, Y"); ?> &nbsp;/&nbsp; <?php the_author_posts_link(); ?> &nbsp;/&nbsp; <?php the_category(', ') ?></span>
    <span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
    <?php the_excerpt();
}
if ( has_post_format( 'video' )) {
    ?>
    <span class="icon-video"></span>
    <span class="sub-title"><?php the_time("F j, Y"); ?> &nbsp;/&nbsp; <?php the_author_posts_link(); ?> &nbsp;/&nbsp; <?php the_category(', ') ?></span>
    <span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
    <?php the_content();
}
if ( has_post_format( 'audio' )) {
    ?>
    <span class="icon-audio"></span>
    <a href="<?php the_permalink() ?>">
    <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-index' ); } ?>
    </a>
    <span class="sub-title"><?php the_time("F j, Y"); ?> &nbsp;/&nbsp; <?php the_author_posts_link(); ?> &nbsp;/&nbsp; <?php the_category(', ') ?></span>
    <span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
    <?php the_content();
}
?>

...when a post format isn't selected I would like to grab this instead:

<!-- Begin excerpt wrap -->
<div class="excerpt_wrap">
<div class="excerpt_inside">

    <?php if ( has_post_thumbnail() ) { ?>   

    <a href="<?php the_permalink() ?>">
    <?php the_post_thumbnail( 'thmb-index' ); ?>
    </a>

    <?php } ?>
    <div class="excerpt_content<?php if ( has_post_thumbnail() ) echo ' with-thumbnail'; ?>">
    <span class="index_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
<span class="sub-title">By <?php the_author_posts_link( ); ?> <span class="sub-title-divider">|</span> <?php the_time('F j, Y'); ?> <span class="sub-title-divider">|</span> <a href="<?php the_permalink(); ?>/#commentlist"><?php comments_number( 'No comments', 'One comment', '% comments' ); ?></a></span>

    <?php the_excerpt(); ?>

    </div>

<!-- End excerpt wrap -->
</div>
</div>
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

I believe you just need to add some "elses" into your php, like so:

if ( has_post_format( 'aside' )) { 
    // do some stuff
} elseif ( has_post_format( 'chat' )) {
    // do some other stuff
} elseif ( has_post_format( 'gallery' )) {
    // do some other stuff
} else {
   // this isn't a post format, so do your final stuff
}

Hope that helps - g'luck!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.