This repository has been archived by the owner on Nov 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp_pagination.php
87 lines (70 loc) · 3.14 KB
/
wp_pagination.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* WordPress Bootstrap Pagination
*/
function wp_bootstrap_pagination( $args = array() ) {
$defaults = array(
'range' => 4,
'custom_query' => FALSE,
'previous_string' => __( 'Previous', 'cooper' ),
'next_string' => __( 'Next', 'cooper' ),
'before_output' => ' <ul class="pagination justify-content-center">',
'after_output' => '</ul>'
);
$args = wp_parse_args(
$args,
apply_filters( 'wp_bootstrap_pagination_defaults', $defaults )
);
$args['range'] = (int) $args['range'] - 1;
if ( !$args['custom_query'] )
$args['custom_query'] = @$GLOBALS['wp_query'];
$count = (int) $args['custom_query']->max_num_pages;
$page = intval( get_query_var( 'paged' ) );
$ceil = ceil( $args['range'] / 2 );
if ( $count <= 1 )
return FALSE;
if ( !$page )
$page = 1;
if ( $count > $args['range'] ) {
if ( $page <= $args['range'] ) {
$min = 1;
$max = $args['range'] + 1;
} elseif ( $page >= ($count - $ceil) ) {
$min = $count - $args['range'];
$max = $count;
} elseif ( $page >= $args['range'] && $page < ($count - $ceil) ) {
$min = $page - $ceil;
$max = $page + $ceil;
}
} else {
$min = 1;
$max = $count;
}
$echo = '';
$previous = intval($page) - 1;
$previous = esc_attr( get_pagenum_link($previous) );
$firstpage = esc_attr( get_pagenum_link(1) );
if ( $firstpage && (1 != $page) )
$echo .= ' <li class="page-item"><a class="page-link" href="' . $firstpage . '" aria-label="Previous"><span aria-hidden="true">' . __( 'First', 'cooper' ) . '</span></a></li>';
if ( $previous && (1 != $page) )
$echo .= '<li class="page-item"><a class="page-link" href="' . $previous . '" title="' . __( 'previous', 'cooper') . '">' . $args['previous_string'] . '</a></li>';
if ( !empty($min) && !empty($max) ) {
for( $i = $min; $i <= $max; $i++ ) {
if ($page == $i) {
$echo .= '<li class="page-item active"><a class="page-link" href="%s"><span class="sr-only">(current)</span>' . str_pad( (int)$i, 2, '0', STR_PAD_LEFT ) . '</span></li>';
} else {
$echo .= sprintf( '<li class="page-item"><a class="page-link" href="%s">%002d<span class="sr-only">(current)</span></a></li>', esc_attr( get_pagenum_link($i) ), $i );
}
}
}
$next = intval($page) + 1;
$next = esc_attr( get_pagenum_link($next) );
if ($next && ($count != $page) )
$echo .= '<li class="page-item"><a class="page-link" href="' . $next . '" title="' . __( 'next', 'cooper') . '">' . $args['next_string'] . '</a></li>';
$lastpage = esc_attr( get_pagenum_link($count) );
if ( $lastpage ) {
$echo .= '<li class="page-item"><a class="page-link" href="' . $lastpage . '" aria-label="Next"><span aria-hidden="true">' . __( 'Last', 'cooper' ) . '</span></a></li>';
}
if ( isset($echo) )
echo $args['before_output'] . $echo . $args['after_output'];
}