T
T
trenton2021-05-10 14:41:02
WordPress
trenton, 2021-05-10 14:41:02

I display product reviews on a separate page, how to make them paginated?

So that for example there were 10 comments on one page, and then there was a transition to the next one.
The code I am using

<div class="container">
  <div class="row">
    <?php if ( !is_user_logged_in()) : ?>   
   <div class="testi-note"><a href="<?php echo get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ) ?>">АВТОРИЗУЙТЕСЬ</a> чтобы оставить свой отзыв.</div>    
    <?php endif; ?>
    </div>
  <div class="row testi-row"> 
    <?php  $comments = get_comments('status=approve&post_type=product'); ?>
    <?php foreach ($comments as $comment) { ?>
         <div class="col-12 testimonial d-flex justify-content-between">
            <div class="testi-author">
              <div class="autor-avatar">
                  <?php $title = get_the_title($comment->comment_post_ID);
                  echo get_avatar( $comment, $size = '100');            
                  ?>            
                  <?php /** привязывает ссылку автора-комментарий к посту **/            
                  $get_the_peralink = get_permalink($comment->comment_post_ID) . "#comment-" . $comment->comment_ID; ?>
                  <div class="author-info">
                        <div class="author-name">
                            <?php /** привязать ссылку на пост комментирования **/
                                echo $comment->comment_author;?>                                            
                        </div>
                       <div class="review-entry">
                       <?php
                        // информация о комментарии
                        $d = "M d, Y";
                        $comment_ID = $comment->comment_ID;
                        $comment_date = get_comment_date( $d, $comment_ID );// можно убрать дату - или все вместе блоки инфы
                        $comment_PID = $comment->comment_post_ID; // можно убрать... число комментариев к конкретной статье
                        echo $comment_date;?>           
                        </div> 
                          <div class="testi-rating">
                            <?php 
                             global $comment;
                            $rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) );
                                echo wc_get_rating_html( $rating );
                                 // WPCS: XSS ok.?>                             
                        </div> 
                  </div>    
               </div> 
            </div>
            <div class="testi-content">
                 <div class="testi-prod-name text-center"><a href="<?php echo $get_the_peralink; ?>"><?php echo  $instance ['read_more_text']; ?>
                         <?php echo $title; ?></a> 
                </div>
                  <div class="testimonial-description">
                     <blockquote class="testimonials-text">
                        <p><?php echo '<span class="comments-widget-entry">' . wp_html_excerpt( $comment->comment_content, 500 ) .
                         '</span>'; ?></p>
                    </blockquote>                    
                  </div> 
                   <div class="comment-count text-center">
                     <?php echo '<span class="comments-widget-entry">- Всего комм:</span> '.get_comments_number
                            ($comment_PID) ?> 
                  </div>      
            </div>
            <div class="testi-thumb">              
                   <?php echo get_the_post_thumbnail( $comment->comment_post_ID, $size = 'medium'); ?>                
            </div>    
</div>
<?php } ?>  
</div>
</div>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question