Skip to content

Instantly share code, notes, and snippets.

@eccentricpixel
Last active August 29, 2015 14:11
Show Gist options
  • Save eccentricpixel/885aaab3710a38c2a9d1 to your computer and use it in GitHub Desktop.
Save eccentricpixel/885aaab3710a38c2a9d1 to your computer and use it in GitHub Desktop.
Custom Pagination for Wordpress
***** for functions.php *****
// custom pagination
function custom_pagination($numpages = '', $pagerange = '', $paged='') {
if (empty($pagerange)) {
$pagerange = 10;
}
global $paged;
if (empty($paged)) {
$paged = 1;
}
if ($numpages == '') {
global $wp_query;
$numpages = $wp_query->max_num_pages;
if(!$numpages) {
$numpages = 1;
}
}
$pagination_args = array(
'base' => add_query_arg('paged','%#%'),
'format' => '',
'total' => $numpages,
'current' => $paged,
'show_all' => False,
'end_size' => 1,
'mid_size' => $pagerange,
'prev_next' => True,
'prev_text' => __('«'),
'next_text' => __('»'),
'type' => 'plain',
'add_args' => false,
'add_fragment' => ''
);
$paginate_links = paginate_links($pagination_args);
if ($paginate_links) {
echo "<nav class='custom-pagination'>";
echo "<span class='page-numbers page-num'>Page " . $paged . " of " . $numpages . "</span> ";
echo $paginate_links;
echo "</nav>";
}
}
****** css
/* ============================================================
CUSTOM PAGINATION
============================================================ */
.custom-pagination span,
.custom-pagination a {
display: inline-block;
padding: 2px 10px;
}
.custom-pagination a {
background-color: @brown;
color: @links;
}
.custom-pagination a:hover {
background-color: @brightRed;
color: @altWhite;
}
.custom-pagination span.page-num {
margin-right: 10px;
padding: 0;
color:@white;
font-weight:200;
}
.custom-pagination span.dots {
padding: 0;
color: gainsboro;
}
.custom-pagination span.current {
background-color: @darkSubMeta;
color: @altWhite;
}
******* for templates - make sure this is included before wp_reset_postdata(); and change the var from $multimedia to whatever your query was called.********
if (function_exists(custom_pagination)) {
custom_pagination($multimedia->max_num_pages,"",$paged);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment