PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Feb 20, 2018 10:11 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 115 posts ]  Go to page Previous  1 ... 4, 5, 6, 7, 8  Next
Author Message
PostPosted: Mon Sep 18, 2017 11:46 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6420
Location: Montreal, Canada
simonmlewis wrote:
Do you mean to add $comments before the final ) ?

Yes, and remove it from where it currently is in that line (assuming you were the one to add it)

simonmlewis wrote:
What do you mean about swapping out calls ??

The code you posted above lists the comments, it doesn't handle pagination. Look at my comment from the weekend where I added some functions to functions.php. You'll need to call those rather than the defaults for the pagination.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Mon Sep 18, 2017 12:16 pm 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4406
Location: United Kingdom
So this in single-product-reviews.php:
Syntax: [ Download ] [ Hide ]
                        <ol class="commentlist">
                                <?php wp_list_comments( apply_filters( 'woocommerce_product_review_list_args', array( 'callback' => 'woocommerce_comments', 'end-callback' => 'jbbg_woocommerce_comments_end' ) ) $comments); ?>
                        </ol>

And this in the footer of functions.php:
Syntax: [ Download ] [ Hide ]
function my_comments_pagination($comments = [], $args = []) {
    echo my_get_comments_pagination($comments, $args);
}

function my_get_comments_pagination($comments = [], $args = []) {
    $navigation = '';
    $args       = wp_parse_args( $args, array(
        'screen_reader_text' => __( 'Comments navigation' ),
    ) );
    $args['echo'] = false;

    // Make sure we get plain links, so we get a string we can work with.
    $args['type'] = 'plain';

    $links = my_paginate_comments_links($comments, $args);

    if ( $links ) {
        $navigation = _navigation_markup( $links, 'comments-pagination', $args['screen_reader_text'] );
    }

    return $navigation;
}


??

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Mon Sep 18, 2017 1:25 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6420
Location: Montreal, Canada
Looks like there's a function missing. Also, hard to comment on what your single page should look like without knowing what it currently looks like. I don't see anything in what you just posted that deals with pagination.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Mon Sep 18, 2017 1:28 pm 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4406
Location: United Kingdom
This is the entire "single-product-reviews.php" file:
Syntax: [ Download ] [ Hide ]
<?php
/**
 * Display single product reviews (comments)
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/single-product-reviews.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see             https://docs.woocommerce.com/document/t ... structure/
 * @author              WooThemes
 * @package     WooCommerce/Templates
 * @version     2.3.2
 */

if ( ! defined( 'ABSPATH' ) ) {
        exit; // Exit if accessed directly
}

global $product;

if ( ! comments_open() ) {
        return;
}

?>
<div id="reviews" class="woocommerce-Reviews">
        <div id="comments">
                <h2 class="woocommerce-Reviews-title"><?php
                        if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' && ( $count = $product->get_review_count() ) ) {
                                /* translators: 1: reviews count 2: product name */
                                printf( esc_html( _n( '%1$s review for %2$s', '%1$s reviews for %2$s', $count, 'woocommerce' ) ), esc_html( $count ), '<span>' . get_the_title() . '</span>' );
                        } else {
                                _e( 'Reviews', 'woocommerce' );
                        }
                ?></h2>

                <?php if ( have_comments() ) : ?>
                <div>As we receive an overwhelming number of reviews on our products, we only display the latest 30 reviews.</div><br/>
                        <ol class="commentlist">
                                <?php wp_list_comments( apply_filters( 'woocommerce_product_review_list_args', array( 'callback' => 'woocommerce_comments', 'end-callback' => 'jbbg_woocommerce_comments_end' ) ) $comments); ?>
                        </ol>

                        <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :
                                echo '<nav class="woocommerce-pagination">';
                                paginate_comments_links( apply_filters( 'woocommerce_comment_pagination_args', array(
                                        'prev_text' => '&larr;',
                                        'next_text' => '&rarr;',
                                        'type'      => 'list',
                                ) ) );
                                echo '</nav>';
                        endif; ?>

                <?php else : ?>

                        <p class="woocommerce-noreviews"><?php _e( 'There are no reviews yet.', 'woocommerce' ); ?></p>

                <?php endif; ?>
        </div>

        <?php if ( get_option( 'woocommerce_review_rating_verification_required' ) === 'no' || wc_customer_bought_product( '', get_current_user_id(), $product->get_id() ) ) : ?>

                <div id="review_form_wrapper">
                        <div id="review_form">
                                <?php
                                        $commenter = wp_get_current_commenter();

                                        $comment_form = array(
                                                'title_reply'          => have_comments() ? __( 'Add a review', 'woocommerce' ) : sprintf( __( 'Be the first to review &ldquo;%s&rdquo;', 'woocommerce' ), get_the_title() ),
                                                'title_reply_to'       => __( 'Leave a Reply to %s', 'woocommerce' ),
                                                'title_reply_before'   => '<span id="reply-title" class="comment-reply-title">',
                                                'title_reply_after'    => '</span>',
                                                'comment_notes_after'  => '',
                                                'fields'               => array(
                                                        'author' => '<p class="comment-form-author">' . '<label for="author">' . esc_html__( 'Name', 'woocommerce' ) . ' <span class="required">*</span></label> ' .
                                                                                '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" aria-required="true" required /></p>',
                                                        'email'  => '<p class="comment-form-email"><label for="email">' . esc_html__( 'Email', 'woocommerce' ) . ' <span class="required">*</span></label> ' .
                                                                                '<input id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" aria-required="true" required /></p>',
                                                ),
                                                'label_submit'  => __( 'Submit', 'woocommerce' ),
                                                'logged_in_as'  => '',
                                                'comment_field' => '',
                                        );

                                        if ( $account_page_url = wc_get_page_permalink( 'myaccount' ) ) {
                                                $comment_form['must_log_in'] = '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a review.', 'woocommerce' ), esc_url( $account_page_url ) ) . '</p>';
                                        }

                                        if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' ) {
                                                $comment_form['comment_field'] = '<div class="comment-form-rating"><label for="rating">' . esc_html__( 'Your rating', 'woocommerce' ) . '</label><select name="rating" id="rating" aria-required="true" required>
                                                        <option value="">'
. esc_html__( 'Rate&hellip;', 'woocommerce' ) . '</option>
                                                        <option value="5">'
. esc_html__( 'Perfect', 'woocommerce' ) . '</option>
                                                        <option value="4">'
. esc_html__( 'Good', 'woocommerce' ) . '</option>
                                                        <option value="3">'
. esc_html__( 'Average', 'woocommerce' ) . '</option>
                                                        <option value="2">'
. esc_html__( 'Not that bad', 'woocommerce' ) . '</option>
                                                        <option value="1">'
. esc_html__( 'Very poor', 'woocommerce' ) . '</option>
                                                </select></div>'
;
                                        }

                                        $comment_form['comment_field'] .= '<p class="comment-form-comment"><label for="comment">' . esc_html__( 'Your review', 'woocommerce' ) . ' <span class="required">*</span></label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" required></textarea></p>';

                                        comment_form( apply_filters( 'woocommerce_product_review_comment_form_args', $comment_form ) );
                                ?>
                        </div>
                </div>

        <?php else : ?>

                <p class="woocommerce-verification-required"><?php _e( 'Only logged in customers who have purchased this product may leave a review.', 'woocommerce' ); ?></p>

        <?php endif; ?>

        <div class="clear"></div>
</div>
 


Which part of the function is missing??

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Mon Sep 18, 2017 2:18 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6420
Location: Montreal, Canada
I don't see the function my_comments_pagination in your functions.php

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Mon Sep 18, 2017 2:56 pm 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4406
Location: United Kingdom
sorry I cannot find a function in this thread called that. getting lost....

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Mon Sep 18, 2017 6:31 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6420
Location: Montreal, Canada
simonmlewis wrote:
sorry I cannot find a function in this thread called that. getting lost....

It's here: viewtopic.php?f=2&t=144184&start=60#p709746
And here: https://imgur.com/gFNIUpG

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Mon Sep 18, 2017 6:35 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6420
Location: Montreal, Canada
simonmlewis wrote:
This is the entire "single-product-reviews.php" file:
Syntax: [ Download ] [ Hide ]
<?php
/**
 * Display single product reviews (comments)
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/single-product-reviews.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see             https://docs.woocommerce.com/document/t ... structure/
 * @author              WooThemes
 * @package     WooCommerce/Templates
 * @version     2.3.2
 */

if ( ! defined( 'ABSPATH' ) ) {
        exit; // Exit if accessed directly
}

global $product;

if ( ! comments_open() ) {
        return;
}

?>
<div id="reviews" class="woocommerce-Reviews">
        <div id="comments">
                <h2 class="woocommerce-Reviews-title"><?php
                        if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' && ( $count = $product->get_review_count() ) ) {
                                /* translators: 1: reviews count 2: product name */
                                printf( esc_html( _n( '%1$s review for %2$s', '%1$s reviews for %2$s', $count, 'woocommerce' ) ), esc_html( $count ), '<span>' . get_the_title() . '</span>' );
                        } else {
                                _e( 'Reviews', 'woocommerce' );
                        }
                ?></h2>

                <?php if ( have_comments() ) : ?>
                <div>As we receive an overwhelming number of reviews on our products, we only display the latest 30 reviews.</div><br/>
                        <ol class="commentlist">
                                <?php wp_list_comments( apply_filters( 'woocommerce_product_review_list_args', array( 'callback' => 'woocommerce_comments', 'end-callback' => 'jbbg_woocommerce_comments_end' ) ) $comments); ?>
                        </ol>

                        <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :
                                echo '<nav class="woocommerce-pagination">';
                                paginate_comments_links( apply_filters( 'woocommerce_comment_pagination_args', array(
                                        'prev_text' => '&larr;',
                                        'next_text' => '&rarr;',
                                        'type'      => 'list',
                                ) ) );
                                echo '</nav>';
                        endif; ?>

                <?php else : ?>

                        <p class="woocommerce-noreviews"><?php _e( 'There are no reviews yet.', 'woocommerce' ); ?></p>

                <?php endif; ?>
        </div>

        <?php if ( get_option( 'woocommerce_review_rating_verification_required' ) === 'no' || wc_customer_bought_product( '', get_current_user_id(), $product->get_id() ) ) : ?>

                <div id="review_form_wrapper">
                        <div id="review_form">
                                <?php
                                        $commenter = wp_get_current_commenter();

                                        $comment_form = array(
                                                'title_reply'          => have_comments() ? __( 'Add a review', 'woocommerce' ) : sprintf( __( 'Be the first to review &ldquo;%s&rdquo;', 'woocommerce' ), get_the_title() ),
                                                'title_reply_to'       => __( 'Leave a Reply to %s', 'woocommerce' ),
                                                'title_reply_before'   => '<span id="reply-title" class="comment-reply-title">',
                                                'title_reply_after'    => '</span>',
                                                'comment_notes_after'  => '',
                                                'fields'               => array(
                                                        'author' => '<p class="comment-form-author">' . '<label for="author">' . esc_html__( 'Name', 'woocommerce' ) . ' <span class="required">*</span></label> ' .
                                                                                '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" aria-required="true" required /></p>',
                                                        'email'  => '<p class="comment-form-email"><label for="email">' . esc_html__( 'Email', 'woocommerce' ) . ' <span class="required">*</span></label> ' .
                                                                                '<input id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" aria-required="true" required /></p>',
                                                ),
                                                'label_submit'  => __( 'Submit', 'woocommerce' ),
                                                'logged_in_as'  => '',
                                                'comment_field' => '',
                                        );

                                        if ( $account_page_url = wc_get_page_permalink( 'myaccount' ) ) {
                                                $comment_form['must_log_in'] = '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a review.', 'woocommerce' ), esc_url( $account_page_url ) ) . '</p>';
                                        }

                                        if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' ) {
                                                $comment_form['comment_field'] = '<div class="comment-form-rating"><label for="rating">' . esc_html__( 'Your rating', 'woocommerce' ) . '</label><select name="rating" id="rating" aria-required="true" required>
                                                        <option value="">'
. esc_html__( 'Rate&hellip;', 'woocommerce' ) . '</option>
                                                        <option value="5">'
. esc_html__( 'Perfect', 'woocommerce' ) . '</option>
                                                        <option value="4">'
. esc_html__( 'Good', 'woocommerce' ) . '</option>
                                                        <option value="3">'
. esc_html__( 'Average', 'woocommerce' ) . '</option>
                                                        <option value="2">'
. esc_html__( 'Not that bad', 'woocommerce' ) . '</option>
                                                        <option value="1">'
. esc_html__( 'Very poor', 'woocommerce' ) . '</option>
                                                </select></div>'
;
                                        }

                                        $comment_form['comment_field'] .= '<p class="comment-form-comment"><label for="comment">' . esc_html__( 'Your review', 'woocommerce' ) . ' <span class="required">*</span></label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" required></textarea></p>';

                                        comment_form( apply_filters( 'woocommerce_product_review_comment_form_args', $comment_form ) );
                                ?>
                        </div>
                </div>

        <?php else : ?>

                <p class="woocommerce-verification-required"><?php _e( 'Only logged in customers who have purchased this product may leave a review.', 'woocommerce' ); ?></p>

        <?php endif; ?>

        <div class="clear"></div>
</div>
 


Which part of the function is missing??

Try this:
Syntax: [ Download ] [ Hide ]
<?php
/**
 * Display single product reviews (comments)
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/single-product-reviews.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see             https://docs.woocommerce.com/document/t ... structure/
 * @author              WooThemes
 * @package     WooCommerce/Templates
 * @version     2.3.2
 */

if ( ! defined( 'ABSPATH' ) ) {
        exit; // Exit if accessed directly
}

global $product;

if ( ! comments_open() ) {
        return;
}

?>
<div id="reviews" class="woocommerce-Reviews">
        <div id="comments">
                <h2 class="woocommerce-Reviews-title"><?php
                        if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' && ( $count = $product->get_review_count() ) ) {
                                /* translators: 1: reviews count 2: product name */
                                printf( esc_html( _n( '%1$s review for %2$s', '%1$s reviews for %2$s', $count, 'woocommerce' ) ), esc_html( $count ), '<span>' . get_the_title() . '</span>' );
                        } else {
                                _e( 'Reviews', 'woocommerce' );
                        }
                ?></h2>

                <?php if ( have_comments() ) : ?>
                <div>As we receive an overwhelming number of reviews on our products, we only display the latest 30 reviews.</div><br/>
                        <ol class="commentlist">
                                <?php
                                $comments = get_comments(['post_id' => get_the_ID()]);
                                $comments = array_filter($comments, function($comment) {
                                    return !empty($comment->comment_content);
                                });
                                wp_list_comments( apply_filters( 'woocommerce_product_review_list_args', array( 'callback' => 'woocommerce_comments', 'end-callback' => 'jbbg_woocommerce_comments_end' ) ), $comments); ?>
                        </ol>

                        <?php if ( get_comment_pages_count($comments) > 1 && get_option( 'page_comments' ) ) :
                                echo '<nav class="woocommerce-pagination">';
                                my_paginate_comments_links($comments, apply_filters( 'woocommerce_comment_pagination_args', array(
                                        'prev_text' => '&larr;',
                                        'next_text' => '&rarr;',
                                        'type'      => 'list',
                                ) ) );
                                echo '</nav>';
                        endif; ?>

                <?php else : ?>

                        <p class="woocommerce-noreviews"><?php _e( 'There are no reviews yet.', 'woocommerce' ); ?></p>

                <?php endif; ?>
        </div>

        <?php if ( get_option( 'woocommerce_review_rating_verification_required' ) === 'no' || wc_customer_bought_product( '', get_current_user_id(), $product->get_id() ) ) : ?>

                <div id="review_form_wrapper">
                        <div id="review_form">
                                <?php
                                        $commenter = wp_get_current_commenter();

                                        $comment_form = array(
                                                'title_reply'          => have_comments() ? __( 'Add a review', 'woocommerce' ) : sprintf( __( 'Be the first to review &ldquo;%s&rdquo;', 'woocommerce' ), get_the_title() ),
                                                'title_reply_to'       => __( 'Leave a Reply to %s', 'woocommerce' ),
                                                'title_reply_before'   => '<span id="reply-title" class="comment-reply-title">',
                                                'title_reply_after'    => '</span>',
                                                'comment_notes_after'  => '',
                                                'fields'               => array(
                                                        'author' => '<p class="comment-form-author">' . '<label for="author">' . esc_html__( 'Name', 'woocommerce' ) . ' <span class="required">*</span></label> ' .
                                                                                '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" aria-required="true" required /></p>',
                                                        'email'  => '<p class="comment-form-email"><label for="email">' . esc_html__( 'Email', 'woocommerce' ) . ' <span class="required">*</span></label> ' .
                                                                                '<input id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" aria-required="true" required /></p>',
                                                ),
                                                'label_submit'  => __( 'Submit', 'woocommerce' ),
                                                'logged_in_as'  => '',
                                                'comment_field' => '',
                                        );

                                        if ( $account_page_url = wc_get_page_permalink( 'myaccount' ) ) {
                                                $comment_form['must_log_in'] = '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a review.', 'woocommerce' ), esc_url( $account_page_url ) ) . '</p>';
                                        }

                                        if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' ) {
                                                $comment_form['comment_field'] = '<div class="comment-form-rating"><label for="rating">' . esc_html__( 'Your rating', 'woocommerce' ) . '</label><select name="rating" id="rating" aria-required="true" required>
                                                        <option value="">'
. esc_html__( 'Rate&hellip;', 'woocommerce' ) . '</option>
                                                        <option value="5">'
. esc_html__( 'Perfect', 'woocommerce' ) . '</option>
                                                        <option value="4">'
. esc_html__( 'Good', 'woocommerce' ) . '</option>
                                                        <option value="3">'
. esc_html__( 'Average', 'woocommerce' ) . '</option>
                                                        <option value="2">'
. esc_html__( 'Not that bad', 'woocommerce' ) . '</option>
                                                        <option value="1">'
. esc_html__( 'Very poor', 'woocommerce' ) . '</option>
                                                </select></div>'
;
                                        }

                                        $comment_form['comment_field'] .= '<p class="comment-form-comment"><label for="comment">' . esc_html__( 'Your review', 'woocommerce' ) . ' <span class="required">*</span></label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" required></textarea></p>';

                                        comment_form( apply_filters( 'woocommerce_product_review_comment_form_args', $comment_form ) );
                                ?>
                        </div>
                </div>

        <?php else : ?>

                <p class="woocommerce-verification-required"><?php _e( 'Only logged in customers who have purchased this product may leave a review.', 'woocommerce' ); ?></p>

        <?php endif; ?>

        <div class="clear"></div>
</div>

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Tue Sep 19, 2017 3:07 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4406
Location: United Kingdom
Oh my goodness, so close. This is what it now does.

It doesn't show the page numbers. So on a product I am on which has three comments, there is no page numbering - perfect.
If set the pagination to 2 per page, it should show a page two, but instead, it 'stops' half way down the page after the description/reviews etc tabs. With debug on, there is no error down there.

If I look in the source code, I can see html, but it's not displaying it. It literally 'stops' after the Reviews tab from rendering anything on screen.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Tue Sep 19, 2017 4:29 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4406
Location: United Kingdom
My bad - smurf is what I added, not smurf.

It works!!!! YAY.

Goodness me. That's amazing. That's a lot of work there isn't it, just to do that.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Tue Sep 19, 2017 4:58 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6420
Location: Montreal, Canada
It's actually not that much in the end. The hard part was figuring out where things were failing. I'm glad everything is working now. Do you understand all the changes and how/why they work?

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Tue Sep 19, 2017 5:13 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4406
Location: United Kingdom
It starts here:
Syntax: [ Download ] [ Hide ]
                        <ol class="commentlist">
                                <?php
// this puts the current Post_id into the $comments variable.
                                $comments = get_comments(['post_id' => get_the_ID()]);
// The comments variable then uses that in an arrange for 'function($comment)'.
And it seems to tell it to only return a result of $comment->comment_content is NOT empty.
                                $comments = array_filter($comments, function($comment) {
                                    return !empty($comment->comment_content);
                                });
// This then hooks into the wp_list_comments functions in single-products-reviews.php, and add the $comments array filter on the end of it.
                                wp_list_comments( apply_filters( 'woocommerce_product_review_list_args', array( 'callback' => 'woocommerce_comments', 'end-callback' => 'jbbg_woocommerce_comments_end' ) ), $comments); ?>
                        </ol>


Onto the function file (and I know it will prob filter out some stuff here):
Syntax: [ Download ] [ Hide ]
/**
Function to set pagination work only for non-empty comment_contents.
Works with single-product-reviews.php in the child theme folder.
 */

// this creates a function, and uses the $comments variable filter along with the default $args.

function my_comments_pagination($comments = [], $args = []) {
    echo my_get_comments_pagination($comments, $args);
}

// don't know about this lot, but I can see it's about arrays of $comments and $args.
function my_get_comments_pagination($comments = [], $args = []) {
    $navigation = '';
    $args       = wp_parse_args( $args, array(
        'screen_reader_text' => __( 'Comments navigation' ),
    ) );
    $args['echo'] = false;

    // Make sure we get plain links, so we get a string we can work with.
    $args['type'] = 'plain';

    $links = my_paginate_comments_links($comments, $args);

    if ( $links ) {
        $navigation = _navigation_markup( $links, 'comments-pagination', $args['screen_reader_text'] );
    }

    return $navigation;
}

function my_paginate_comments_links($comments = [], $args = []) {
    global $wp_rewrite;

    if ( ! is_singular() )
        return;

    $page = get_query_var('cpage');
    if ( !$page )
        $page = 1;
    $max_page = get_comment_pages_count(empty($comments) ? null : $comments);
    $defaults = array(
        'base' => add_query_arg( 'cpage', '%#%' ),
        'format' => '',
        'total' => $max_page,
        'current' => $page,
        'echo' => true,
        'add_fragment' => '#comments'
    );
    if ( $wp_rewrite->using_permalinks() )
        $defaults['base'] = <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>(<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>(get_permalink()) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged');

    $args = wp_parse_args( $args, $defaults );
    $page_links = paginate_links($args);
    if($args['echo'])
    echo $page_links;
    else
    return $page_links;
    }


So a lot of it is going over my head, such as smurf (shows as smurf on here... the trailing stuff.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Tue Sep 19, 2017 5:18 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6420
Location: Montreal, Canada
Well, a lot of it is standard WordPress code, which we don't necessarily need to get into. What I wanted to highlight, really, was the differences between the original functions and their modified versions. There's really one chief difference.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Tue Sep 19, 2017 5:24 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4406
Location: United Kingdom
It has caused a problem I just noticed.
If a comment is awaiting approval, it shows on the Reviews tab (when not logged in, so it' snot down to admin login) as "your comment is awaiting approval.
Something in that function I think is shows comments in the reviews area, even if they are not published yet.

I've switched it back, so will trial it again in the staging area.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Tue Sep 19, 2017 5:25 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6420
Location: Montreal, Canada
You can pass that in as an argument to get_comments

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 115 posts ]  Go to page Previous  1 ... 4, 5, 6, 7, 8  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group