Не получается пагинация для комментариев
Пытаюсь подключить пагинацию эти кодом
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(); }
Пытаюсь Пагинацию сделать, что-то не пойму
Делал недавно, может поможет..
$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 ] );
Еще больше запутался
Список сокращается а вот пагинация не показывается
Не знаю что такое '$filter', но предполагаю что должно быть 'filter' без $
Кстати да ошибка. Но не из-за этого. Я так думаю что-то сюда нужно
foreach( $comments as $comment ){
Ну да, ошибка на ошибке..
**$comquery** = new WP_Comment_Query( $args ); foreach( **$comments** as $comment ){
Посмотри еще..
$query = new WP_Comment_Query; $comments = $query->query( $args );
а у тебя..
$comquery = new WP_Comment_Query( $args );
Так тоже нет
$comquery = new WP_Comment_Query; $comments = $comquery->query( $args );
get_the_title($comment->comment_post_ID)
А у тебя $comment->post_title
Не помогло
Коменты выдаются, пагинация не выдается почему-то
Скинь код последний, я у себя на локалке проверю
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(); }
Грубая ошибка if( $comments = get_comments( $args ));{
Все ровно нет пагинации
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(); }
$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 );
то работать не будет.
Спасибо большое. Была проблема в $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 );
Рад был помочь, number дважды )
спс )
Если интересно можешь посмотреть что я делаю
Красиво. Футер пришей к низу. Кнопка "оставить комментарий" гуляет.
Спасибо. Ты профиль пользователя посмотри
Нашел