Forums

[resolved] Recent Post Loop (3 posts)

  1. Saint Jermaine
    Member
    Posted 1 year ago #

    Hi guys,

    I have a self-hosted WordPress Blog and I'm having a problem showing more than one recent post in my sidebar.

    Here is the code I'm using to display my most recent blog post in my sidebar--

    <h4>Latest Post</h4>
    
    			<?php query_posts("post_per_page=3"); the_post(); ?>
    
    			<div class="sidebar-post">
    				<p class="date"><?php the_date(); ?></p>
    				<p><img src="<?php echo get_post_meta($post->ID, "Thumbnail", true);?>" /></p>
    				<h5><a>"><?php the_title(); ?></a></h5>
    				<p><?php the_excerpt(); ?></p>
    			</div>
    
    			<?php wp_reset_query(); ?>

    [please use backticks or the 'code' button to mark code; it will keep the code intact.
    you can already see that the link html got corrupted by posting code the wrong way.]

    It works fine, except that no matter what number I put in the "post_per_page=3", it only returns one post. I would like to display at least 3 recent posts. Can anyone help?

    Thanks a lot!

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    it is actually the plural: 'posts_per_page'

    also, you need a loop structure after the query:

    <?php query_posts("posts_per_page=3"); while( have_posts() ) : the_post(); ?>

    and then at the end:

    <?php endwhile;
    wp_reset_query(); ?>
  3. Saint Jermaine
    Member
    Posted 1 year ago #

    That worked perfectly. Thank you so much!

Topic Closed

This topic has been closed to new replies.

About this Topic