Use the following code just before “<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>” in your code:
query_posts( 'posts_per_page=3' );
And Place the paging code after “endif” statement.
Thanks, chandanonline4u. My only issue now is what is the paging code? I tried to copy from the 2012 code, but I’m not sure which code. Also, if I use query_posts(); will the number of post be based on the what is in the reading admin panel?
Use the following code just after loop:
<?php
global $wp_query;
if ( $wp_query->max_num_pages > 1 ) : ?>
<nav id="<?php echo $nav_id; ?>">
<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyeleven' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?></div>
</nav><!-- #nav-above -->
<?php endif; ?>
No, If you define “posts_per_page” argument in query_posts then it will override reading settings in admin panel.
Nice! So here is what I have
<section id="vid_content">
<?php
query_posts( 'posts_per_page=3' );
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php echo'<article class="vids">';
echo'<h3>';
the_title();
echo'</h3>';
the_content();
echo'
<p>#thatshitgray <a href="http://www.twitter.com/grayareabrand">@grayareabrand</a> |
<a href="http://www.facebook.com/grayareabrand">Facebook </a></p>';
echo'</article>'; ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<?php
global $wp_query;
if ( $wp_query->max_num_pages > 1 ) : ?>
<nav id="<?php echo $nav_id; ?>">
<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyeleven' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?></div>
</nav><!-- #nav-above -->
<?php endif; ?>
</section>
When I click the next button, the page navigates to the next page but it shows the same post. Weird right? Here is the page so you can make sure I’m not crazy. http://www.grayareabrand.com/blog/
Replace the currently used query_posts code with the following code:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array('posts_per_page'=>3,'paged'=>$paged));
And Place paging code just before closing endif statement.
Thank you very much! Solve my issue. In case anyone needs the final code here it is:
<section id="vid_content">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array('posts_per_page'=>3,'paged'=>$paged));
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php echo'<article class="vids">';
echo'<h3>';
the_title();
echo'</h3>';
the_content();
echo'
<p>#thatshitgray <a href="http://www.twitter.com/grayareabrand">@grayareabrand</a> |
<a href="http://www.facebook.com/grayareabrand">Facebook </a></p>';
echo'</article>'; ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<?php
global $wp_query;
if ( $wp_query->max_num_pages > 1 ) : ?>
<nav id="<?php echo $nav_id; ?>">
<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyeleven' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?></div>
</nav><!-- #nav-above -->
<?php endif; ?>
</section>