I added the below code to my index.php and it's working fine. Then I added it to my type-[post_type].php file and it's still displaying the code for the last post on the page. I can't figure out why. Should I be doing it a different way?

    <?php if( $wp_query->current_post < $wp_query->post_count-1 ): ?>
    <img src="<?php bloginfo('template_directory'); ?>/images/fezhr.png" />
    <?php endif; ?>

Here is my loop for one of the post types:

    <?php if (have_posts()) : ?>

<div id="content">
    <div id="latestLinks">
        <div id="listHead">Latest</div>
        <div id="listLinks"><a href="http://www.flesheatingzipper.com/" id="linksA">EVERYTHING</a> | <a href="http://www.flesheatingzipper.com/games/" id="linksG">GAMES</a> | <a href="http://www.flesheatingzipper.com/entertainment/" id="linksE">ENTERTAINMENT</a> | <a href="http://www.flesheatingzipper.com/tech/" id="linksT">TECH</a> | <a href="http://www.flesheatingzipper.com/podcasts/" id="linksP">PODCASTS</a></div>
        <br style="clear:both;" />

        <?php while (have_posts()) : the_post(); ?>
        <div class="postWrapper">
        <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1> 

            <div class="postDetails">
                <div class="postDetailsLeft">Posted by: <?php the_author_posts_link(); ?> on <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?></div>
                <div class="postDetailsRight"><?php if(function_exists('the_views')) { the_views(); } ?> | <a href="<?php comments_link(); ?>"><?php comments_number('0 Comments', '1 Comment', '% Comments'); ?></a></div>
                <br style="clear:both;" />

        if ( has_post_thumbnail() ) {
            $image_id = get_post_thumbnail_id();
            $image_url = wp_get_attachment_image_src($image_id, 'large', true);
            echo '<a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '"><img src="' . $image_url[0] . '" title="' . get_the_title($post->ID) . '" alt="' . get_the_title($post->ID) . '" class="aligncenter" /></a>';

           the_content('Read the rest of this article...');
           $postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
           echo $postOutput;
        <br style="clear:both;" />
        <?php if( $wp_query->current_post < $wp_query->post_count-1 ): ?>
        <img src="<?php bloginfo('template_directory'); ?>/images/fezhr.png" class="fezHR" />
        <?php endif; ?>

        <?php endwhile; ?>

            <?php wp_pagenavi(); ?>

    <?php else : ?>
<div id="content">
        <img src="<?php bloginfo('template_directory'); ?>/images/FEZ404.png" /><br /><br />
        <p>God dammit! FEZ why do you always ruin all the fun. Sorry the page you requested has been eaten! You will just have to find something else, deal with it.</p>

    <?php endif; ?>

Your template file should be named archive-[post_type].php. Check out the template hierarchy.

  • I know the codex says that but when I change them it goes back to using index.php. – kel Mar 13 '11 at 21:21
  • Lemme just confirm a few things - the code you provided is used in 'the loop' to print an image, so long as it's not the last post? And you're trying to replicate this in a template file for a custom post type? When you tried type-[post_type].php, are you sure that file was used (and not index.php) when you viewed the custom post type archive? – TheDeadMedic Mar 13 '11 at 22:08
  • Sorry, I'm using a template redirect in my functions.php file to find those type-[post_type].php. I don't understand why it wouldn't work still. Also I am 100% sure that it was using index.php even after taking the code out from my functions.php. – kel Mar 14 '11 at 2:33
  • Could you post a little more code? Perhaps a sample of your loop? – TheDeadMedic Mar 14 '11 at 10:31
  • Updated with my loop code in the original post. BTW, I have temporarily fixed with jQuery, just don't want it to be permanent. – kel Mar 15 '11 at 5:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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