Support » Themes and Templates » Display Recent Posts in Single.php

Display Recent Posts in Single.php

  • 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>
    <?php endwhile; ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • Still looking for some assistance with this, thanks!

    Would still really appreciate any help, thanks!

    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?


    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.

    Or have a look at wp_get_archives() maybe?

    With wp_get_archives can I still pull custom values such as

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Display Recent Posts in Single.php’ is closed to new replies.
Skip to toolbar