WordPress.org

Ready to get started?Download WordPress

Forums

Display Recent Posts in Single.php (7 posts)

  1. Riboflavin
    Member
    Posted 7 years ago #

    Hi all!

    I use this code on my homepage to display recent posts made on my site. I wanted to use this code to display recent posts on single pages as well, but when I use it, it only displays the current post rather than the latest posts. I'm sure I am just doing something wrong with the loop but I can't figure it out. Any help is really appreciated!

    <?php while (have_posts()) : the_post(); ?>
    <div class="wide3">
    <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
    <a href="<?php the_permalink() ?>" class="product">
    <?php echo c2c_get_custom('pic'); ?>
    <span><?php echo c2c_get_custom('price'); ?></span>
    </a>
    </div>
    <?php endwhile; ?>
  2. Riboflavin
    Member
    Posted 7 years ago #

    Still looking for some assistance with this, thanks!

  3. Riboflavin
    Member
    Posted 7 years ago #

    Would still really appreciate any help, thanks!

  4. Riboflavin
    Member
    Posted 7 years ago #

    Ok, I changed my first loop line to this:

    <?php query_posts('showposts=3'); while (have_posts()) : the_post(); ?>

    and now it displays the 3 most recent posts in the header properly, however now the main post on the page is being displayed as the most recent post. How do I set it back to display the proper post for the single page?

    Thanks!

  5. Adam Brown
    Member
    Posted 7 years ago #

    You're trying to call the loop twice on the same page, but for different posts. That's not going to work the way you want it to.

    If you're just trying to display recent posts in the sidebar, are you using the Sidebar Widgets plugin? That would make your life easier.

  6. Chris_K
    Member
    Posted 7 years ago #

    Or have a look at wp_get_archives() maybe?

  7. Riboflavin
    Member
    Posted 7 years ago #

    With wp_get_archives can I still pull custom values such as

    <?php echo c2c_get_custom('pic'); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic