How to Add Pagination in Your Custom Template

1.Add following codes in your page template before starting posts query.

 $args = array(

                'post_type'  => 'post',

                'meta_key' => '_thumbnail_id',

                'posts_per_page' => 7,
                'paged' => $paged);

            $query = new WP_Query($args);

2.After end of While loop and before close of IF statement paste following code.

echo '
    <div id="wp_pagination">
        <a class="first page button" href="'.get_pagenum_link(1).'">&laquo;</a>
        <a class="previous page button" href="'.get_pagenum_link(($curpage-1 > 0 ? $curpage-1 : 1)).'">&lsaquo;</a>';
        for($i=1;$i<=$query->max_num_pages;$i++)
            echo '<a class="'.($i == $curpage ? 'active ' : '').'page button" href="'.get_pagenum_link($i).'">'.$i.'</a>';
        echo '
        <a class="next page button" href="'.get_pagenum_link(($curpage+1 <= $query->max_num_pages ? $curpage+1 : $query->max_num_pages)).'">&rsaquo;</a>
        <a class="last page button" href="'.get_pagenum_link($query->max_num_pages).'">&raquo;</a></div> ';
Thanks

Comments

Popular posts from this blog

Create New Project in Laravel

How to Get Access of Database of Dynamic Site Without cPanel Details

How to Create Secondary Menu in Squarespace