Skip to content

Instantly share code, notes, and snippets.

@dingo-d
Last active December 26, 2015 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dingo-d/34814b5835a8bb595958 to your computer and use it in GitHub Desktop.
Save dingo-d/34814b5835a8bb595958 to your computer and use it in GitHub Desktop.
Custom made pagination for wordpress
<?php
global $wp_query;
$total_pages = $wp_query->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
$permalink_structure = get_option('permalink_structure');
$format = empty( $permalink_structure ) ? '?paged=%#%' : 'page/%#%/';
echo '
<section id="pagination" class="clearfix">
<div class="container">
<div class="pagination">';
$pagination_output = paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => $format,
'current' => $current_page,
'total' => $total_pages,
'prev_text' => esc_html__('Previous', 'yourtheme'),
'next_text' => esc_html__('Next', 'yourtheme'),
'type' => 'array',
));
foreach ($pagination_output as $link) {
$link_parts=array();
$link_exploded = explode('?', $link,2);
$link_parts[] = ' '.$link_exploded[0];
if (isset($link_exploded[1])){
$link_parts[] = str_replace('?', '&amp;', $link_exploded[1]);
}
$link_echo = implode('?', $link_parts);
echo $link_echo;
}
echo '
</div>
</div>
</section>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment