items_per_page = (int) $items_per_page; } /** * @return int */ public function get_items_per_page() { return $this->items_per_page; } /** * @param int $total_items */ public function set_total_items( $total_items ) { $this->total_items = (int) $total_items; } /** * @return int */ public function get_total_items() { return $this->total_items; } /** * @return int */ public function get_total_pages() { return ceil( $this->get_total_items() / $this->get_items_per_page() ); } /** * @param int $page */ public function set_current_page( $page ) { $this->current_page = (int) $page; } /** * @return int */ public function get_current_page() { return $this->current_page; } /** * @return null|string */ public function get_first_page_url() { $url = null; if ( 2 < $this->get_current_page() ) { $url = remove_query_arg( 'paged', $this->get_current_url() ); } return $url; } /** * @return null|string */ public function get_previous_page_url() { $url = null; if ( 1 < $this->get_current_page() ) { $url = add_query_arg( 'paged', $this->get_current_page() - 1, $this->get_current_url() ); } return $url; } /** * @return null|string */ public function get_next_page_url() { $url = null; if ( $this->get_current_page() < $this->get_total_pages() ) { $url = add_query_arg( 'paged', $this->get_current_page() + 1, $this->get_current_url() ); } return $url; } /** * @return null|string */ public function get_last_page_url() { $url = null; if ( $this->get_current_page() < $this->get_total_pages() - 1 ) { $url = add_query_arg( 'paged', $this->get_total_pages(), $this->get_current_url() ); } return $url; } /** * @return string */ private function get_current_url() { if ( ! $this->current_url ) { $removable_query_args = wp_removable_query_args(); $this->current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); $this->current_url = remove_query_arg( $removable_query_args, $this->current_url ); } return $this->current_url; } }