Title: pagination
Last modified: August 21, 2016

---

# pagination

 *  [jeff234](https://wordpress.org/support/users/jeff234/)
 * (@jeff234)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/pagination-78/)
 * hello
    how to add pagination to following codes:
 *     ```
       <div class="gridcontainer">
       <h1 class="entry-title"><?php the_title(); ?></h1>
       <?php
       // Grid Parameters
       $counter = 1; // Start the counter
       $grids = 5; // Grids per row
       $titlelength = 20; // Length of the post titles shown below the thumbnails
       // The Query
       $args=array (
       	'post_type' => 'post',
       	'posts_per_page' => -1
       	);
       $the_query = new WP_Query($args);
   
       // The Loop
       while ( $the_query->have_posts() ) :
       	$the_query->the_post();
   
       // Show all columns except the right hand side column
       if($counter != $grids) :
       ?>
       <div class="griditemleft">
       	<div class="postimage">
       		<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a>
       	</div><!-- .postimage -->
       	<h2 class="postimage-title">
       		<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
       		<?php if (mb_strlen($post->post_title) > $titlelength)
       			{ echo mb_substr(the_title($before = '', $after = '', FALSE), 0, $titlelength) . ' ...'; }
       		else { the_title(); } ?>
       		</a>
       	</h2>
       </div><!-- .griditemleft -->
       <?php
   
       // Show the right hand side column
       elseif($counter == $grids) :
       ?>
       <div class="griditemright">
       	<div class="postimage">
       		<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a>
       	</div><!-- .postimage -->
       	<h2 class="postimage-title">
       		<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
       		<?php if (mb_strlen($post->post_title) > $titlelength)
       			{ echo mb_substr(the_title($before = '', $after = '', FALSE), 0, $titlelength) . ' ...'; }
       		else { the_title(); } ?>
       		</a>
       	</h2>
       </div><!-- .griditemright -->
   
       <div class="clear"></div>
       <?php
       $counter = 0;
       endif;
       $counter++;
       endwhile;
       wp_reset_postdata();
       ?>
   
       </div><!-- .gridcontainer -->
       ```
   

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/pagination-78/#post-4019381)
 * try to add the ‘paged’ parameter to the query:
 *     ```
       $args=array (
       	'post_type' => 'post',
       	'posts_per_page' => -1,
       	'paged' => get_query_var( 'paged' )
       	);
       ```
   
 * and after the `endwhile;`, add for example:
 *     ```
       next_posts_link( 'next', $the_query->max_num_pages );
       previous_posts_link( 'previous', $the_query->max_num_pages );
       ```
   
 * generaly review [http://codex.wordpress.org/Pagination‎](http://codex.wordpress.org/Pagination‎)
 *  Thread Starter [jeff234](https://wordpress.org/support/users/jeff234/)
 * (@jeff234)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/pagination-78/#post-4019412)
 * thanks! if i select the page as front page in Reading Settings, the pagination
   stop working, any idea how to fix this? and how do i styling pagination?

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

The topic ‘pagination’ is closed to new replies.

## Tags

 * [pagination](https://wordpress.org/support/topic-tag/pagination/)

 * 2 replies
 * 2 participants
 * Last reply from: [jeff234](https://wordpress.org/support/users/jeff234/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/pagination-78/#post-4019412)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
