• Resolved webheadmusic

    (@webheadmusic)


    My sidebar.php file has the following code. The problem is that only 1 post is being returned. Any help is greatly appreciated.

    <aside>
    
    		<?php get_search_form(); ?>
    
    		<nav>
    			<?php wp_nav_menu(array('menu' => 'Main Nav Menu')); ?>
    		</nav>
    
    		<div class="widget latest-post">
    
    			<h4>Latest Post</h4>
    
    			<?php query_posts("post_per_page=2"); the_post(); ?>
    
    			<div class="sidebar-post">
    				<p class="date"><?php the_date(); ?></p>
    				<h5><?php the_title(); ?></h5>
    				<p><?php the_content(); ?></p>
    			</div>
    
    			<?php wp_reset_query(); ?>
    
    		</div>
    		<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('Sidebar Widgets')) : else : ?>
    
    		    <!-- All this stuff in here only shows up if you DON'T have any widgets active in this zone -->
    
    		<?php endif; ?>
    
    	</aside>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter webheadmusic

    (@webheadmusic)

    Thanks very much. I have now added the s in posts_per_page. I’m still baffled though. I have 2 published posts and I want them to both show up in the sidebar. Only one is showing up.

    my_site

    my mistake – I stopped checking after the first spotted error;

    actually your code does not have ‘the loop’, i.e. the while( have_posts() )endwhile is missing;

    change to:

    <?php query_posts("posts_per_page=2"); while( have_posts() ) : the_post(); ?>
    
    			<div class="sidebar-post">
    				<p class="date"><?php the_date(); ?></p>
    				<h5><?php the_title(); ?></h5>
    				<p><?php the_content(); ?></p>
    			</div>
    
    			<?php endwhile; wp_reset_query(); ?>
    Thread Starter webheadmusic

    (@webheadmusic)

    Awesome! You totally rock! That’s perfect. Two posts in sidebar. Thank you so much.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Only getting 1 post in sidebar – need 2’ is closed to new replies.