# get_comment_pages_count()

URL: https://chugunov.pro/api-wordpress/functions/get_comment_pages_count/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 2.7.0.

## Сигнатура

```php
get_comment_pages_count( WP_Comment[] $comments = null, int $per_page = null, bool $threaded = null ): int
```

## Описание

Вычисляет общее количество страниц комментариев.

## Параметры

- `$comments` `WP_Comment[]` — необязательный, по умолчанию `null`. Массив объектов WP_Comment. По умолчанию $wp_query->comments.
- `$per_page` `int` — необязательный, по умолчанию `null`. Количество комментариев на странице. По умолчанию берётся значение переменной запроса comments_per_page, одноимённой опции или 1 (именно в таком порядке).
- `$threaded` `bool` — необязательный, по умолчанию `null`. Управление плоскими или древовидными комментариями. По умолчанию берётся значение опции thread_comments.

## Возвращаемое значение

`int`

## Исходный код

Файл: `wp-includes/comment.php:984`

```php
function get_comment_pages_count( $comments = null, $per_page = null, $threaded = null ) {
	global $wp_query;

	if ( null === $comments && null === $per_page && null === $threaded && ! empty( $wp_query->max_num_comment_pages ) ) {
		return $wp_query->max_num_comment_pages;
	}

	if ( ( ! $comments || ! is_array( $comments ) ) && ! empty( $wp_query->comments ) ) {
		$comments = $wp_query->comments;
	}

	if ( empty( $comments ) ) {
		return 0;
	}

	if ( ! get_option( 'page_comments' ) ) {
		return 1;
	}

	if ( ! isset( $per_page ) ) {
		$per_page = (int) get_query_var( 'comments_per_page' );
	}
	if ( 0 === $per_page ) {
		$per_page = (int) get_option( 'comments_per_page' );
	}
	if ( 0 === $per_page ) {
		return 1;
	}

	if ( ! isset( $threaded ) ) {
		$threaded = get_option( 'thread_comments' );
	}

	if ( $threaded ) {
		$walker = new Walker_Comment();
		$count  = ceil( $walker->get_number_of_root_elements( $comments ) / $per_page );
	} else {
		$count = ceil( count( $comments ) / $per_page );
	}

	return (int) $count;
}
```

## История изменений

- 2.7.0 — Introduced.

## Связанные

Использует: [`get_query_var`](https://chugunov.pro/api-wordpress/functions/get_query_var/), `WP_Query`, `Walker::get_number_of_root_elements`, [`get_option`](https://chugunov.pro/api-wordpress/functions/get_option/).
Используется в: [`get_the_comments_navigation`](https://chugunov.pro/api-wordpress/functions/get_the_comments_navigation/), [`get_next_comments_link`](https://chugunov.pro/api-wordpress/functions/get_next_comments_link/), [`paginate_comments_links`](https://chugunov.pro/api-wordpress/functions/paginate_comments_links/), [`wp_list_comments`](https://chugunov.pro/api-wordpress/functions/wp_list_comments/), [`comments_template`](https://chugunov.pro/api-wordpress/functions/comments_template/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/get_comment_pages_count/
