WordPress.org

Forums

Display 3 Recent Posts in Single.php (3 posts)

  1. Riboflavin
    Member
    Posted 7 years ago #

    Hi all, I would really appreciate help with this, I have been trying to get it to work for weeks. What I am trying to do, is display the 3 latest posts near the top of my page in single posts. What I am using is this code:

    <?php $posts = get_posts( "numberposts=3" ); ?>
    <?php if( $posts ) : ?>
    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
    <div class="wide3">
    <p><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></p>
    <a href="<?php the_permalink() ?>" class="product">
    <?php echo c2c_get_custom('pic'); ?>
    <span><?php echo c2c_get_custom('price'); ?></span>
    </a>
    </div>
    <?php endforeach; ?>
    <?php endif; ?>

    This code works great, and displays my 3 latest posts properly, however in the main portion of the page, where the current post is suppose to be displayed, it displays the most recent posts rather than the one for this particular single page. I guess what I need is a way for it to call the single post again since its stuck thinking about most recent posts. Thanks for any help!

  2. Riboflavin
    Member
    Posted 7 years ago #

    Still need some help with this :)

  3. moshu
    Member
    Posted 7 years ago #

    You may want to read about the use of multiple Loops:
    The_Loop

Topic Closed

This topic has been closed to new replies.

About this Topic