Skip to content

Instantly share code, notes, and snippets.

@coreyweb
Created April 18, 2012 00:24
Show Gist options
  • Save coreyweb/2410083 to your computer and use it in GitHub Desktop.
Save coreyweb/2410083 to your computer and use it in GitHub Desktop.
WordPress Pagination Replacement
// Some custom styling examples
/* category pagination */
.pagination {
margin: 0 0 10px 0; padding: 10px 0; border-top: 1px solid #ccc;
}
.page-numbers {
font-family:proxima-nova,Arial, Helvetica, sans-serif;
font-weight: normal;
font-size: 15px;
}
.page-numbers.current {
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-khtml-border-radius: 5px;
border-radius: 5px;
color: #fff;
background: #c00;
padding: 3px 10px;
}
.page-numbers.dots {
padding: 3px 5px;
}
a.page-numbers {
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-khtml-border-radius: 5px;
border-radius: 5px;
color: #fff;
padding: 3px 10px;
background: #000;
text-decoration: none;
}
a.page-numbers:hover {
background: #888;
}
a.prev, a.next {
text-transform: uppercase;
}
// Improved Category pagination (instead of previous and next)
// Reference: http://codex.wordpress.org/Function_Reference/paginate_links
function pagination($prev = 'Prev', $next = 'Next') {
global $wp_query, $wp_rewrite;
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
$pagination = array(
'base' => @add_query_arg('paged','%#%'),
'format' => '',
'total' => $wp_query->max_num_pages,
'current' => $current,
'prev_text' => __($prev),
'next_text' => __($next),
'mid_size' => 4,
'end_size' => 4,
'type' => 'plain'
);
if( $wp_rewrite->using_permalinks() )
$pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );
if( !empty($wp_query->query_vars['s']) )
$pagination['add_args'] = array( 's' => get_query_var( 's' ) );
echo paginate_links( $pagination );
};
// Place this in your template(s) (wherever you'd like pagination to replace the standard prev/next links in WordPress)
<div class="pagination"><?php pagination('Prev', 'Next'); ?></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment