Having trouble with pagination. (3 posts)

  1. mmaumio
    Posted 2 years ago #

    I'm running WordPress 3.6.1 the latest version.

    Trying to paginate through WP_Query class. This's not working.
    I'm providing the code to have a look.

    I'm sure I did something silly that's out of my sight.

    [ Moderator note: please wrap code in backticks or use the code button. ]

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
    		 	$args = array ( 'posts_per_page' => 3, 'paged' => $paged );
    		 	$the_query = new WP_Query($args); // note that the $paged function doesn't seem to be working
    		<?php if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>
            <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    			<h2><a>"><?php the_title(); ?></a></h2>
                  <p> <B>Date posted: <?php the_date(); ?></B> </p>
    			<?php include ('wp-includes/meta.php' ); ?>
    			<div class="entry">
    				<?php //the_content() ?>
                    <?php the_excerpt(); ?>
    	<?php endwhile; ?>
    	<div class="nav-previous alignleft"><?php next_posts_link(); ?></div>
    	<div class="nav-next alignright"><?php previous_posts_link(); ?></div>
        <?php wp_reset_postdata(); ?>
    	<?php else : ?>
    		<h2>Not Found</h2>
    	<?php endif; ?>


  2. keesiemeijer
    Posted 2 years ago #

    Add the $max_pages parameter to the next_post_link() function:

    div class="nav-previous alignleft"><?php next_posts_link( __( 'Next Page &raquo;' ), $the_query->max_num_pages ); ?></div>
    <div class="nav-next alignright"><?php previous_posts_link(); ?></div>
  3. mmaumio
    Posted 2 years ago #

    Thanks a lot for the help.
    It almost worked.

    Except a single issue.
    When I hit the next page link it remains on the same page(blog page) raher than moving into the page2.

    Please suggest me something.

Topic Closed

This topic has been closed to new replies.

About this Topic