Carbon_Pagination_Posts::get_page_url()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 4
Bugs 1 Features 0
Metric Value
cc 2
eloc 4
c 4
b 1
f 0
nc 2
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
1
<?php
2
/**
3
 * Carbon Pagination - posts pagination class.
4
 * Provides the pagination for non-singular post loops (index, search, archive).
5
 *
6
 * @uses Carbon_Pagination_HTML
7
 */
8
class Carbon_Pagination_Posts extends Carbon_Pagination_HTML {
9
10
	/**
11
	 * Constructor.
12
	 * Creates and configures a new pagination with the provided settings.
13
	 *
14
	 * @param array $args Configuration options to modify the pagination settings.
15
	 */
16 6
	public function __construct( $args = array() ) {
17 6
		global $wp_query;
18
19
		// specify the default args for the Posts pagination
20 6
		$this->default_args = array(
21
			// get the total pages from the query
22 6
			'total_pages' => max( $wp_query->max_num_pages, 1 ),
23
24
			// get the current page from the query
25 6
			'current_page' => max( get_query_var( 'paged' ), 1 ),
26
27
			// modify the text of the previous page link
28 6
			'prev_html' => '<a href="{URL}" class="paging-prev">' . esc_html__( '« Previous Entries', 'crb' ) . '</a>',
29
30
			// modify the text of the next page link
31 6
			'next_html' => '<a href="{URL}" class="paging-next">' . esc_html__( 'Next Entries »', 'crb' ) . '</a>',
32
		);
33
34 6
		parent::__construct( $args );
35 6
	}
36
37
	/**
38
	 * Get the URL to a certain page.
39
	 *
40
	 * @param int $page_number The page number.
41
	 * @param string $old_url Optional. The URL to add the page number to.
42
	 * @return string $url The URL to the page number.
43
	 */
44 4
	public function get_page_url( $page_number, $old_url = '' ) {
45 4
		$pages = $this->get_pages();
46 4
		$page = isset( $pages[ $page_number ] ) ? $pages[ $page_number ] : 0;
47 4
		return get_pagenum_link( $page );
48
	}
49
50
}