Wednesday, March 26, 2014

Include pagination in my custom blogs page

<!-- Add the pagination functions here. -->

<div class="nav-previous alignleft"><?php next_posts_link( '&laquo; Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts &raquo;' ); ?></div>

----------------------------------------

<div id="pagination">
        <?php
// grab the current query parameters
$query_string = $_SERVER['QUERY_STRING'];

// The $base variable stores the complete URL to our page, including the current page arg

// if in the admin, your base should be the admin URL + your page
$base = get_site_url() . '/search-results/?' . remove_query_arg('x', $query_string) . '%_%';

// if on the front end, your base is the current page
//$base = get_permalink( get_the_ID() ) . '?' . remove_query_arg('p', $query_string) . '%_%';

echo paginate_links( array(
'base' => $base, // the base URL, including query arg
'format' => '&x=%#%', // this defines the query parameter that will be used, in this case "p"
'prev_text' => __('&laquo; Previous'), // text for previous page
'next_text' => __('Next &raquo;'), // text for next page
'total' => $total_pages, // the total number of pages we have
'current' => $page, // the current page
'end_size' => 1,
'mid_size' => 5,
));
}
?>
      </div>

No comments:

Post a Comment