Yoast\WP\SEO\Helpers

Pagination_Helper::get_paginated_url()publicYoast 1.0

Builds a paginated URL.

Метод класса: Pagination_Helper{}

Хуков нет.

Возвращает

Строку. The paginated URL.

Использование

$Pagination_Helper = new Pagination_Helper();
$Pagination_Helper->get_paginated_url( $url, $page, $add_pagination_base, $pagination_query_name );
$url(строка) (обязательный)
The un-paginated URL of the current archive.
$page(строка) (обязательный)
The page number to add on to $url for the $link tag.
$add_pagination_base(true|false)
Whether to add the pagination base (page) to the url.
По умолчанию: true
$pagination_query_name(строка)
The name of the query argument that holds the current page.
По умолчанию: 'page'

Код Pagination_Helper::get_paginated_url() Yoast 22.1

public function get_paginated_url( $url, $page, $add_pagination_base = true, $pagination_query_name = 'page' ) {
	$wp_rewrite = $this->wp_rewrite_wrapper->get();

	$key_query_loop = $this->get_key_query_loop();
	if ( $key_query_loop ) {
		$pagination_query_name = $key_query_loop;
	}

	if ( $wp_rewrite->using_permalinks() && ! $key_query_loop ) {
		$url_parts      = \wp_parse_url( $url );
		$has_url_params = \array_key_exists( 'query', $url_parts );

		if ( $has_url_params ) {
			// We need to first remove the query params, before potentially adding the pagination parts.
			\wp_parse_str( $url_parts['query'], $query_parts );

			$url = \trailingslashit( \remove_query_arg( \array_keys( $query_parts ), $url ) );

			if ( $add_pagination_base ) {
				$url .= \trailingslashit( $wp_rewrite->pagination_base );
			}

			// We can now re-add the query params, after appending the last pagination parts.
			return \add_query_arg( $query_parts, \user_trailingslashit( $url . $page ) );
		}

		$url = \trailingslashit( $url );
		if ( $add_pagination_base ) {
			$url .= \trailingslashit( $wp_rewrite->pagination_base );
		}

		return \user_trailingslashit( $url . $page );
	}

	return \add_query_arg( $pagination_query_name, $page, \user_trailingslashit( $url ) );
}