WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi I have created my index.php file as a blog template and on my website I am creating a page using that template.The problem is that by doing it this way pagination is not working anymore.It worked when index.php was my home page.This is my code:

$index_query = new WP_Query(array(
                             if($index_query->have_posts()): while($index_query->have_posts()): $index_query->the_post();?>
                                    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                    <h3><span>Posted on <span> <?php echo get_the_date(); ?> in <?php the_category(); ?> by <?php the_author_link(); ?></h3>
                                    <a href="<?php the_permalink(); ?>" class="box">
                                            if(function_exists('has_post_thumbnail') && has_post_thumbnail()){
                                        <span><?php comments_number("0") ?></span>
                                    <?php the_excerpt(); ?>
                                    <a href="<?php the_permalink(); ?>" class="read">Continue Reading</a>
                           <?php endwhile; endif;?>

   global $wp_query;
                        $total_pages = $wp_query->max_num_pages;

                        if($total_pages > 1){
                            $current_page = max(1 , get_query_var('paged'));
                            echo paginate_links(array(
                                'base' => get_pagenum_link(1) . '%_%',
                                'format' => '/page/%#%',
                                'current' => $current_page,
                                'total' => $total_pages

How can I make pagination work on page templates?

share|improve this question
Try using query_posts() instead of WP_Query and pass the paged parameter too. – Joshua Abenazer Aug 24 '12 at 8:48
Thank you that did it – Nistor Alexandru Aug 24 '12 at 8:57
up vote 1 down vote accepted

Try add the "page" var to the WP_Query statement

$index_query = new WP_Query(array(
'paged'=>max(1 , get_query_var('paged')),

Is it the loop that is not paging through the posts, (it just displays the same ones no matter what page you are on? Or is the actual pagination just not displaying any links?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.