pagination.php ➔ spurs_pagination()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 2
dl 0
loc 42
rs 9.248
c 0
b 0
f 0
1
<?php
2
/**
3
 * Pagination layout.
4
 *
5
 * @package spurs
6
 */
7
8
// Exit if accessed directly.
9
defined( 'ABSPATH' ) || exit;
10
11
if ( ! function_exists( 'spurs_pagination' ) ) {
12
13
	function spurs_pagination( $args = [], $class = 'pagination' ) {
14
15
		if ( $GLOBALS['wp_query']->max_num_pages <= 1 ) {
16
			return;
17
		}
18
19
		$args = wp_parse_args( $args,
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $args. This often makes code more readable.
Loading history...
20
			array(
21
				'mid_size'           => 2,
22
				'prev_next'          => true,
23
				'prev_text'          => __( '&laquo;', 'spurs' ),
24
				'next_text'          => __( '&raquo;', 'spurs' ),
25
				'screen_reader_text' => __( 'Posts navigation', 'spurs' ),
26
				'type'               => 'array',
27
				'current'            => max( 1, get_query_var( 'paged' ) ),
28
			)
29
		);
30
31
		$links = paginate_links( $args );
32
33
		?>
34
35
		<nav aria-label="<?php echo $args['screen_reader_text']; ?>">
36
            <div class="container">
37
                <ul class="pagination justify-content-center mt-5">
38
39
				<?php
40
				foreach ( $links as $key => $link ) {
41
					?>
42
					<li class="page-item <?php echo strpos( $link, 'current' ) ? 'active' : '' ?>">
43
						<?php echo str_replace( 'page-numbers', 'page-link', $link ); ?>
44
					</li>
45
					<?php
46
				}
47
				?>
48
49
			</ul>
50
            </div>
51
		</nav>
52
53
		<?php
54
	}
55
}
56