Created
April 28, 2021 13:00
-
-
Save ulziibat-n/80de6ed4597ed31125b64ad2f85d3770 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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