Не получается пагинация для комментариев

Пытаюсь подключить пагинацию эти кодом

    global $user_ID;
  $us_id = $_GET['uid'];
  if ( is_user_logged_in() && $us_id > 0 && $us_id !== "" && is_numeric($us_id)) { }
  else { $us_id = $user_ID;}
  $author->ID = $us_id;

  $no = 5; $paged = get_query_var( 'paged' ) ?: 1; $offset = ( $paged - 1 ) * $no;

   $args = array('number'  => $no, 'user_id' => $author->ID );
   if( $comments = get_comments( $args ));{

   $args_count = array('user_id' => $author->ID, 'count' => true );
   $comments_count = get_comments( $args_count );

	 if ( (int) $comments_count < 1 ) {
	   echo '<ol><pre>Сообщений нет</pre></ol>';
	 } else {
	   echo '<ol>';

	$comquery = new WP_Comment_Query( $args );

	// foreach( $comquery->comments as $comment ){

	foreach( $comments as $comment ){
	  $comm_link = get_comment_link( $comment->comment_ID );
	  $comm_short_txt = mb_substr( strip_tags( $comment->comment_content ), 0, 120 ) .'...';

	  echo '<li><div class="info-pf-vuvod">' . $comment->post_title .': <br/><br/>';
	  echo '<i class="fa fa-comments-o"></i> <a rel="nofollow" href="'. $comm_link .'">'. $comm_short_txt .'</a></div></li>';
	}
	  echo '</ol>';
}
$found_comments = $comquery->max_num_pages;
$total_pages=ceil($found_comments/$no);
echo '<div class="pagination pf-paging-navi pf-list">' . paginate_links(array('$filter' => get_pagenum_link(1) . '%_% ', 'format' => '?paged=%#%', 'current' => $paged, 'total' => $found_comments, 'prev_text' => '«', 'next_text' => '»', 'type' => 'list', )) . '</div>';
wp_reset_query();
}
Заметки к вопросу:
pfilan 1.1 года назад

Нашел

'number'  => $no,
pfilan 1.1 года назад

Пытаюсь Пагинацию сделать, что-то не пойму

mi13 1.1 года назад

Делал недавно, может поможет..

$pagenum = (isset($_GET['pagenum']) && intval($_GET['pagenum'])>1) ? intval($_GET['pagenum']) : 1;
$offset = ($pagenum - 1) * 10;
$paged_url_patt = home_url( preg_replace( '/[?&].*/', '', $_SERVER['REQUEST_URI'] ) ) .'?pagenum=%#%';
$args = array(
		'orderby' => 'comment_date',
		'order'   => 'DESC',
		'status'  => 'approve',
		'type'    => 'comment',
		'post_status' => 'publish',
		'number'  => 10,
		'offset'  => $offset,
		'callback' => 'mytheme_comment_for_all',
		'end-callback' => 'calback_all_comment',
		'no_found_rows'  => false
	);
$com = '';
$com = 
$query    = new WP_Comment_Query;
$comments = $query->query( $args );
function calback_all_comment($comment) {
	echo '<p>К записи <span class="widgetlink"><a rel="nofollow" href="'. get_permalink($comment->comment_post_ID) .'">' . get_the_title($comment->comment_post_ID) . '</a></span></p><hr>';
}
$max_pages = (int) $query->max_num_pages;
if($pagenum<1 || $pagenum>$max_pages) wp_redirect(home_url('404'));

$paginate_links = paginate_links( [
	'base'    => $paged_url_patt,
	'current' => $pagenum,
	'total'   => $max_pages
] );
pfilan 1.1 года назад

Еще больше запутался smile

Список сокращается а вот пагинация не показывается

mi13 1.1 года назад

Не знаю что такое '$filter', но предполагаю что должно быть 'filter' без $

pfilan 1.1 года назад

Кстати да ошибка. Но не из-за этого. Я так думаю что-то сюда нужно

foreach( $comments as $comment ){
mi13 1.1 года назад

Ну да, ошибка на ошибке..

**$comquery** = new WP_Comment_Query( $args );

	foreach( **$comments** as $comment ){
pfilan 1.1 года назад

Я так пробывал smile

foreach( $comquery as $comment )

Наверно так нужно

foreach( $comquery->comments as $comment)

Но пагинации нет все ровно

mi13 1.1 года назад

Посмотри еще..

$query    = new WP_Comment_Query;
$comments = $query->query( $args );

а у тебя..

$comquery = new WP_Comment_Query( $args );
pfilan 1.1 года назад

Так тоже нет

$comquery = new WP_Comment_Query;
	$comments = $comquery->query( $args );
mi13 1.1 года назад

get_the_title($comment->comment_post_ID)
А у тебя $comment->post_title

pfilan 1.1 года назад

Не помогло

pfilan 1.1 года назад

Коменты выдаются, пагинация не выдается почему-то

mi13 1.1 года назад

Скинь код последний, я у себя на локалке проверю

pfilan 1.1 года назад
  global $user_ID;
  $us_id = $_GET['uid'];
  if ( is_user_logged_in() && $us_id > 0 && $us_id !== "" && is_numeric($us_id)) { }
  else { $us_id = $user_ID;}
  $author->ID = $us_id;

  $no = 5; $paged = get_query_var( 'paged' ) ?: 1; $offset = ( $paged - 1 ) * $no;

   $args = array('number'  => $no, 'user_id' => $author->ID );
   if( $comments = get_comments( $args ));{

   $args_count = array('user_id' => $author->ID, 'count' => true );
   $comments_count = get_comments( $args_count );

	 if ( (int) $comments_count < 1 ) {
	   echo '<ol><pre>Сообщений нет</pre></ol>';
	 } else {
	   echo '<ol>';

	$comquery = new WP_Comment_Query;
	$comments = $comquery->query( $args );

	// foreach( $comquery->comments as $comment ){

	foreach( $comquery->comments as $comment){
	  $comm_link = get_comment_link( $comment->comment_ID );
	  $comm_short_txt = mb_substr( strip_tags( $comment->comment_content ), 0, 120 ) .'...';

	  echo '<li><div class="info-pf-vuvod">' . $comment->post_title .': <br/><br/>';
	  echo '<i class="fa fa-comments-o"></i> <a rel="nofollow" href="'. $comm_link .'">'. $comm_short_txt .'</a></div></li>';
	}
	  echo '</ol>';
}
$found_comments = $comquery->max_num_pages;
$total_pages=ceil($found_comments/$no);
echo '<div class="pagination pf-paging-navi pf-list">' . paginate_links(array('filter' => get_pagenum_link(1) . '%_% ', 'format' => '?paged=%#%', 'current' => $paged, 'total' => $found_comments, 'prev_text' => '«', 'next_text' => '»', 'type' => 'list', )) . '</div>';
wp_reset_query();
}
mi13 1.1 года назад

Грубая ошибка if( $comments = get_comments( $args ));{

pfilan 1.1 года назад

Все ровно нет пагинации sad

  global $user_ID;
  $us_id = $_GET['uid'];
  if ( is_user_logged_in() && $us_id > 0 && $us_id !== "" && is_numeric($us_id)) { }
  else { $us_id = $user_ID;}
  $author->ID = $us_id;

  $no = 5; $paged = get_query_var( 'paged' ) ?: 1; $offset = ( $paged - 1 ) * $no;

   $args = array('number'  => $no, 'user_id' => $author->ID );
   $comments = get_comments( $args );

   $args_count = array('user_id' => $author->ID, 'count' => true );
   $comments_count = get_comments( $args_count );

	 if ( (int) $comments_count < 1 ) {
	   echo '<ol><pre>Сообщений нет</pre></ol>';
	 } else {
	   echo '<ol>';

	$comquery = new WP_Comment_Query;
	$comments = $comquery->query( $args );

	// foreach( $comquery->comments as $comment ){

	foreach( $comquery->comments as $comment){
	  $comm_link = get_comment_link( $comment->comment_ID );
	  $comm_short_txt = mb_substr( strip_tags( $comment->comment_content ), 0, 120 ) .'...';

	  echo '<li><div class="info-pf-vuvod">' . $comment->post_title .': <br/><br/>';
	  echo '<i class="fa fa-comments-o"></i> <a rel="nofollow" href="'. $comm_link .'">'. $comm_short_txt .'</a></div></li>';
	}
	  echo '</ol>';
}
$found_comments = $comquery->max_num_pages;
$total_pages=ceil($found_comments/$no);
echo '<div class="pagination pf-paging-navi pf-list">' . paginate_links(array('filter' => get_pagenum_link(1) . '%_% ', 'format' => '?paged=%#%', 'current' => $paged, 'total' => $found_comments, 'prev_text' => '«', 'next_text' => '»', 'type' => 'list', )) . '</div>';
wp_reset_query();

}
mi13 1.1 года назад
  $no = 5; 
  $paged = (isset($_GET['paged']) && intval($_GET['paged'])>1) ? intval($_GET['paged']) : 1; 
  $offset = ( $paged - 1 ) * $no;

   $args = array(
		'orderby' => 'comment_date',
		'order'   => 'DESC',
		'status'  => 'approve',
		'type'    => 'comment',
		'post_status' => 'publish',
		'number'  => $no,
		'offset'  => $offset,
		'no_found_rows'  => false
	);

	$comquery = new WP_Comment_Query;
	$comments = $comquery->query( $args );
echo '<ol>';
	foreach( $comments as $comment){
	  $comm_link = get_comment_link( $comment->comment_ID );
	  $comm_short_txt = mb_substr( strip_tags( $comment->comment_content ), 0, 120 ) .'...';

	  echo '<li><div class="info-pf-vuvod">' . $comment->post_title .': <br/><br/>';
	  echo '<i class="fa fa-comments-o"></i> <a rel="nofollow" href="'. $comm_link .'">'. $comm_short_txt .'</a></div></li>';
	}
echo '</ol>';
$found_comments = (int) $comquery->max_num_pages;
echo $found_comments;
echo '<div class="pagination pf-paging-navi pf-list">' . paginate_links(array('format' => '?paged=%#%', 'current' => $paged, 'total' => $found_comments, 'prev_text' => '«', 'next_text' => '»' )) . '</div>';

Вот с такими аргументами работает, то есть есть какие то обязательные аргументы.
А если $args = array('number' => $no,'offset' => $offset );
то работать не будет.

pfilan 1.1 года назад

Спасибо большое. Была проблема в $args = array(

$args = array(
'number'  => $no, 
'orderby' => 'comment_date',    
'order'   => 'DESC',
'status'  => 'approve',
'type'    => 'comment',
'post_status' => 'publish', 
'offset'  => $offset,   
'no_found_rows'  => false, 
'user_id' => $author->ID );
mi13 1.1 года назад

Рад был помочь, number дважды )

pfilan 1.1 года назад

спс )

pfilan 1.1 года назад

Если интересно можешь посмотреть что я делаю

mi13 1.1 года назад

Красиво. Футер пришей к низу. Кнопка "оставить комментарий" гуляет.

pfilan 1.1 года назад

Спасибо. Ты профиль пользователя посмотри