0

I am using my home page to show all my posts. Therefore I use WP_Query.

When I click on the pagination, the url changes but not the page content.

This is my code,

<?php 
    $paged = (get_query_var('page')) ? get_query_var('page') : 1;
    $args = array( 'post_type' => 'post', 'posts_per_page' => 10, 'page' => $paged );
    $wp_query = new WP_Query($args);
    while ( have_posts() ) : the_post(); ?>
        <div class="home-post">
            <h2 class="entry-title"><?php the_title(); ?></h2>
            <div class="thumb-img">
                <img src="<?php the_post_thumbnail(); ?>" alt="" />
                <div class="thumb-hover"></div>
            </div>
            <!--/ thumb image -->
            <div class="post-excerpt">
                <?php the_excerpt(__('(more…)')); ?>
            </div>
            <!--/ post excerpt -->
            <a class="readmore" href="<?php the_permalink(); ?>">Continue Reading</a>
        </div>
        <!--/ home post -->
    <?php endwhile; ?>
    <div class="home-pagination">
        <!-- then the pagination links -->
        <?php next_posts_link( '&larr; Older posts', $wp_query ->max_num_pages); ?>
        <?php previous_posts_link( 'Newer posts &rarr;' ); ?>
    </div>
6
  • Change 'page' to 'paged' in the query arguments.
    – Milo
    Dec 23, 2015 at 5:24
  • 1
    You should not be running custom queries in place of the main query on the home page any type of archive page. It will always cause headaches with pagination Dec 23, 2015 at 6:49
  • @PieterGoosen then what is the better way to do this. I need to show all posts in my home page. Show 10 posts at a time and for other posts I need to use pagination Dec 23, 2015 at 7:00
  • Simply use the default loop Dec 23, 2015 at 7:18
  • 1
    Also, never ever use $wp_query as a local variable, this breaks the main query object which in turn breaks many many other functions Dec 23, 2015 at 7:20

1 Answer 1

-1

try this for get_query_var

<?php  $paged = get_query_var( 'paged', 1 ); ?>

For more information check this url

https://codex.wordpress.org/Function_Reference/get_query_var

1
  • Why is the syntax wrong, page is a valid value as well. Also, you do not need to pass the second parameter Dec 23, 2015 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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