• Resolved Saint Jermaine

    (@saint-jermaine)


    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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael

    (@alchymyth)

    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(); ?>
    Thread Starter Saint Jermaine

    (@saint-jermaine)

    That worked perfectly. Thank you so much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Recent Post Loop’ is closed to new replies.