|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
4
|
|
|
exit; // Exit if accessed directly |
|
5
|
|
|
} |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* A component class for rendering a bootstrap pagination. |
|
9
|
|
|
* |
|
10
|
|
|
* @since 1.0.0 |
|
11
|
|
|
*/ |
|
12
|
|
|
class AUI_Component_Pagination { |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Build the component. |
|
16
|
|
|
* |
|
17
|
|
|
* @param array $args |
|
18
|
|
|
* |
|
19
|
|
|
* @return string The rendered component. |
|
20
|
|
|
*/ |
|
21
|
|
|
public static function get( $args = array() ) { |
|
22
|
|
|
global $wp_query; |
|
23
|
|
|
|
|
24
|
|
|
$defaults = array( |
|
25
|
|
|
'mid_size' => 2, |
|
26
|
|
|
'prev_text' => '<i class="fas fa-chevron-left"></i>', |
|
27
|
|
|
'next_text' => '<i class="fas fa-chevron-right"></i>', |
|
28
|
|
|
'screen_reader_text' => __( 'Posts navigation' ), |
|
29
|
|
|
'before_page_number' => '', |
|
30
|
|
|
'after_page_number' => '', |
|
31
|
|
|
'type' => 'array', |
|
32
|
|
|
'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1 |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Parse incoming $args into an array and merge it with $defaults |
|
37
|
|
|
*/ |
|
38
|
|
|
$args = wp_parse_args( $args, $defaults ); |
|
39
|
|
|
|
|
40
|
|
|
$output = ''; |
|
41
|
|
|
|
|
42
|
|
|
// Don't print empty markup if there's only one page. |
|
43
|
|
|
if ( $args['total'] > 1 ) { |
|
44
|
|
|
|
|
45
|
|
|
// Set up paginated links. |
|
46
|
|
|
$links = paginate_links( $args ); |
|
47
|
|
|
|
|
48
|
|
|
// make the output bootstrap ready |
|
49
|
|
|
$links_html = "<ul class='pagination m-0 p-0'>"; |
|
50
|
|
|
if ( ! empty( $links ) ) { |
|
51
|
|
|
foreach ( $links as $link ) { |
|
52
|
|
|
$active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
53
|
|
|
$links_html .= "<li class='page-item $active'>"; |
|
54
|
|
|
$links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
55
|
|
|
$links_html .= "</li>"; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
$links_html .= "</ul>"; |
|
59
|
|
|
|
|
60
|
|
|
if ( $links ) { |
|
61
|
|
|
$output .= '<section class="px-0 py-2 w-100">'; |
|
62
|
|
|
$output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
63
|
|
|
$output .= '</section>'; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
67
|
|
|
$output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if ( $output ) { |
|
71
|
|
|
if ( ! empty( $args['before_paging'] ) ) { |
|
72
|
|
|
$output = $args['before_paging'] . $output; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
if ( ! empty( $args['after_paging'] ) ) { |
|
76
|
|
|
$output = $output . $args['after_paging']; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return $output; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
} |