Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Pagination In Wordpress

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 314
    Comment on it

    We can add pagination to our page.

    In wordpress we can split multiple post in different pages.

    We can set how many post per page we want

    When multiple loops are used in a theme template file only one loop, the main loop, can be paginated.

    <?php
                $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
                $args = array(
                'post_type' => 'video',
                'posts_per_page' => 6,
                'paged' => $paged
                );
                $query = new WP_Query($args);
                if($query->have_posts()) {
                while($query->have_posts()) {
                $query->the_post(); 
                // custom content ?>
    

    This is the loop in which we add the paged variable and number of post we want per page.

    I have done 6.

    <?php
                    $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') ),
                    'total' => $query->max_num_pages
                    ) );
                    ?>
    

    This code is put where we want to apply pagination usually at the bottom of the page.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: