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.

I would REALLY appreciate some help with this, I have been working on it for a while and am so close to done I can taste it.

I need each post format excerpt to have the same excerpt code as the default excerpt (used without post formats) which is provided as "Code 1". This MUST contain the excerpt_wrap and exerpt_inside along with the conditional div class. Basically, everything in this code... simply figure out how to integrate it into the second code everywhere it says "CODE GOES HERE"...

Code 1:

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

<!-- No post format -->

            <?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>

Code 2:

<?php get_header(); ?>



<div id="container">

<div id="post_content2">

<div id="main_index">

<div class="main_adjust"> 



<!-- Grab posts -->

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







            <!-- Post formats -->

<?php

if ( has_post_format( 'aside' )) {

CODE GOES HERE

}

elseif ( has_post_format( 'chat' )) {

CODE GOES HERE

}

elseif ( has_post_format( 'gallery' )) {

CODE GOES HERE

}

elseif ( has_post_format( 'image' )) {

CODE GOES HERE

}

elseif ( has_post_format( 'link' )) {

CODE GOES HERE

}

elseif ( has_post_format( 'quote' )) {

CODE GOES HERE

}

elseif ( has_post_format( 'status' )) {

CODE GOES HERE

}

elseif ( has_post_format( 'video' )) {

CODE GOES HERE

}

elseif ( has_post_format( 'audio' )) {

CODE GOES HERE

}

else {

$format = get_post_format();

if ( false === $format ) {

 ?>



<!-- Begin excerpt wrap -->

        <div class="excerpt_wrap">

          <div class="excerpt_inside">





<!-- No post format -->

            <?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>



<?php } // ending the if ( false === $format ) ... 



    } // end else



        ?>

<?php endwhile; ?>







        <!-- Next/Previous entries -->

       <div class="mp_archive">

          <div id="more_posts">

            <div class="oe">

              <?php next_posts_link('&laquo; Older') ?>

            </div>

            <div class="re">

              <?php previous_posts_link ('Newer &raquo;') ?>

            </div>

          </div>

          </div>





</div>

</div>

</div>



  <?php get_sidebar(); ?>



</div>

</div>



<?php get_footer(); ?>
share|improve this question

1 Answer 1

up vote 2 down vote accepted

You can utilize the Wordpress function get_template_part();

Create several template files in your theme directory called content-POST_FORMAT_TYPE.php - Example: content-gallery.php and content-chat.php

if(has_post_format('gallery'))
    get_template_part('content', 'gallery');
elseif(has_post_format('chat')
    get_template_part('content', 'chat');
else
    the_content();

This approach makes your code blocks reusable in multiple templates. Hope this helps you out.

share|improve this answer
    
I'll try it tomorrow and let you know, thanks! –  AndrettiMilas Sep 15 '11 at 3:55
    
THANKS! This helped a lot. –  AndrettiMilas Sep 15 '11 at 14:38

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.