Skip to content

Instantly share code, notes, and snippets.

@ulziibat-n
Created April 28, 2021 13:00
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 ulziibat-n/80de6ed4597ed31125b64ad2f85d3770 to your computer and use it in GitHub Desktop.
Save ulziibat-n/80de6ed4597ed31125b64ad2f85d3770 to your computer and use it in GitHub Desktop.
if ( ! function_exists( 'dimative_the_pagination_default' ) ) {
/**
* Default Pagination
*
* @see https://www.billerickson.net/custom-pagination-links/
*
* @param int $max_num_pages Max num pages.
* @param string $classes Pagination Classes.
*/
function dimative_the_pagination_default( $max_num_pages = null, $classes = '' ) {
global $wp_query;
if ( null === $max_num_pages ) {
$max_num_pages = $wp_query->max_num_pages;
}
if ( $max_num_pages <= 1 ) {
return;
}
$big = 999999999; // need an unlikely integer.
$pages = paginate_links(
array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var( 'paged' ) ),
'total' => $max_num_pages,
'type' => 'array',
'prev_next' => apply_filters( 'dimative_filter_pagination_default_prev_next', true ),
'prev_text' => apply_filters( 'dimative_filter_pagination_default_prev_text', esc_html__( 'Previous', 'inflation' ) ),
'next_text' => apply_filters( 'dimative_filter_pagination_default_next_text', esc_html__( 'Next', 'inflation' ) ),
)
);
$allowed_html = array(
'a' => array(
'href' => array(),
'class' => array(),
),
'span' => array(
'class' => array(),
),
);
if ( is_array( $pages ) ) {
echo '<ul class="pagination-default ' . esc_attr( $classes ) . '">';
foreach ( $pages as $page ) {
$li_class = '';
// Active class.
$has_current = preg_match( '/(current)/', $page, $matches );
if ( $has_current ) {
$li_class = 'pagination-item-active';
}
// Disabled class.
$has_current = preg_match( '/(dots)/', $page, $matches );
if ( $has_current ) {
$li_class = 'pagination-item-disabled';
}
echo '<li class="pagination-item ' . esc_attr( $li_class ) . '">' . wp_kses( $page, $allowed_html ) . '</li>';
}
echo '</ul>';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment