Skip to content

Instantly share code, notes, and snippets.

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 benbasty/13a90692a90a729f641b92e29bf7abac to your computer and use it in GitHub Desktop.
Save benbasty/13a90692a90a729f641b92e29bf7abac to your computer and use it in GitHub Desktop.
Wordpress navigation in Bootstrap style
// Usage in a template
\YourCompany\Helpers\Pagination::render(get_query_var('paged'), $loop->max_num_pages);
<?php
/**
* Class for rendering Wordpress navigation in Bootstrap style
*/
namespace YourCompany\Helpers;
Class Pagination
{
public static function render($paged, $max_num_pages, $echo = true)
{
$largerInt = 999999999; // need an unlikely integer
$pages = paginate_links([
'base' => str_replace($largerInt, '%#%', esc_url(get_pagenum_link($largerInt))),
'format' => '?paged=%#%',
'current' => max(1, $paged),
'total' => $max_num_pages,
'type' => 'array',
'prev_next' => true,
'prev_text' => __('« Prev'),
'next_text' => __('Next »'),
]);
if (is_array($pages)) {
$paged = ($paged == 0) ? 1 : $paged;
$pagination = '<ul class="pagination">';
foreach ($pages as $page) {
//$page = strip_tags($page);
$pagination .= '<li class="page-item">' . str_replace('page-numbers', 'page-link', $page) . '</li>';
}
$pagination .= '</ul>';
if ($echo) {
echo $pagination;
} else {
return $pagination;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment