1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Carbon Pagination - comments pagination class. |
4
|
|
|
* Provides the pagination for comments within a post/page. |
5
|
|
|
* |
6
|
|
|
* @uses Carbon_Pagination_HTML |
7
|
|
|
*/ |
8
|
|
|
class Carbon_Pagination_Comments 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
|
|
|
|
18
|
|
|
// specify the default args for the Comments pagination |
19
|
6 |
|
$this->default_args = array( |
20
|
|
|
// specify the total number of pages as retrieved above |
21
|
6 |
|
'total_pages' => $this->get_total_comment_pages(), |
22
|
|
|
|
23
|
|
|
// get the current comments page from the query |
24
|
6 |
|
'current_page' => max( get_query_var( 'cpage' ), 1 ), |
25
|
|
|
|
26
|
|
|
// modify the text of the previous page link |
27
|
6 |
|
'prev_html' => '<a href="{URL}" class="paging-prev">' . esc_html__( '« Older Comments', 'crb' ) . '</a>', |
28
|
|
|
|
29
|
|
|
// modify the text of the next page link |
30
|
6 |
|
'next_html' => '<a href="{URL}" class="paging-next">' . esc_html__( 'Newer Comments »', 'crb' ) . '</a>', |
31
|
|
|
); |
32
|
|
|
|
33
|
6 |
|
parent::__construct( $args ); |
34
|
6 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Retrieve the total number of comment pages. |
38
|
|
|
* |
39
|
|
|
* @return int $total Total number of comment pages. |
40
|
|
|
*/ |
41
|
4 |
|
public function get_total_comment_pages() { |
42
|
4 |
|
global $wp_query; |
43
|
|
|
|
44
|
|
|
// get max page from query |
45
|
4 |
|
if ( ! empty( $wp_query->max_num_comment_pages ) ) { |
46
|
3 |
|
$max_page = $wp_query->max_num_comment_pages; |
47
|
3 |
|
} |
48
|
|
|
|
49
|
|
|
// if there is no max page in the query, calculate it |
50
|
4 |
|
if ( empty( $max_page ) ) { |
51
|
4 |
|
$max_page = get_comment_pages_count(); |
52
|
4 |
|
} |
53
|
|
|
|
54
|
4 |
|
return intval( max( $max_page, 1 ) ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get the URL to a certain page. |
59
|
|
|
* |
60
|
|
|
* @param int $page_number The page number. |
61
|
|
|
* @param string $old_url Optional. The URL to add the page number to. |
62
|
|
|
* @return string $url The URL to the page number. |
63
|
|
|
*/ |
64
|
4 |
|
public function get_page_url( $page_number, $old_url = '' ) { |
65
|
4 |
|
return get_comments_pagenum_link( $page_number + 1 ); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
} |