Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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(
                                    'posts_per_page'=>'3',
                                    'post_type'=>'post'
                             ));
                             if($index_query->have_posts()): while($index_query->have_posts()): $index_query->the_post();?>
                                <div>
                                    <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">
                                        <?php
                                            if(function_exists('has_post_thumbnail') && has_post_thumbnail()){
                                                the_post_thumbnail();
                                            }
                                        ?>
                                        <span><?php comments_number("0") ?></span>
                                    </a>
                                    <?php the_excerpt(); ?>
                                    <a href="<?php the_permalink(); ?>" class="read">Continue Reading</a>
                                </div>
                           <?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
2  
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

1 Answer 1

up vote 1 down vote accepted

Try add the "page" var to the WP_Query statement

$index_query = new WP_Query(array(
'posts_per_page'=>'3',
'paged'=>max(1 , get_query_var('paged')),
'post_type'=>'post'
));

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

 
discard

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.