0

I have a problem figuring out the pagination. Using the information i found in this Wordpress Pagination Not Working - Always Showing First Pages Content thread, i've managed to set up pagination on my page. The code looks like this:

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
$args = array(
    'posts_per_page' => 10,
    'paged' => $paged,
    'cat' => 6,
);
$your_query = new WP_Query( $args );

if ( $your_query->have_posts() ) { ?>
    <div id="blog-masonry" class="row">
    <?php while ( $your_query->have_posts() ) {
        $your_query->the_post();
        get_template_part( 'template-parts/content', get_post_format() );
    }
} else {
    echo 'Sorry, no posts found.';
}
?>

The problem is the only way i can access the pages is by typing e.g. /page/2 in browser. How do i actually display the pagination (< 1 2 3 >)?

Sorry if the question is dumb, i'm a total newbie.

SOLUTION (as suggested by Vishit): add pagination after the loop

            $big = 999999999; // need an unlikely integer
             echo paginate_links( array(
            'base' => str_replace( $big, '%#%', esc_url( 
             get_pagenum_link( $big ) ) ),
            'format' => '?paged=%#%',
            'current' => max( 1, get_query_var('paged') ),
            'prev_text'          => __('Prev'),
            'next_text'          => __('Next'),
            'total' => $your_query->max_num_pages
1
                $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                $args_blog = array(
                'post_type' => 'post',
                'paged' => $paged,
                'posts_per_page' =>  get_option('posts_per_page ')
                );
                $query_blog = new WP_Query( $args_blog );
                if($query_blog->have_posts()) : while($query_blog->have_posts()) : $query_blog->the_post();

                 $big = 999999999; // need an unlikely integer
                 echo paginate_links( array(
                'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                'format' => '?paged=%#%',
                'current' => max( 1, get_query_var('paged') ),
                'prev_text'          => __('Prev'),
                'next_text'          => __('Next'),
                'total' => $query_blog->max_num_pages
            ) );
  • what is that? a dump of code is not a good answer. What does the code do and why?, what was the original problem the code solves? – Mark Kaplun Jul 13 '17 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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