Wordpress Pagination Links - how do I modify this?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Wordpress Pagination Links - how do I modify this?

Post by Celauran »

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.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Wordpress Pagination Links - how do I modify this?

Post by simonmlewis »

So this in single-product-reviews.php:

Code: Select all

			<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:

Code: Select all

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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Wordpress Pagination Links - how do I modify this?

Post by Celauran »

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.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Wordpress Pagination Links - how do I modify this?

Post by simonmlewis »

This is the entire "single-product-reviews.php" file:

Code: Select all

<?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/template-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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Wordpress Pagination Links - how do I modify this?

Post by Celauran »

I don't see the function my_comments_pagination in your functions.php
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Wordpress Pagination Links - how do I modify this?

Post by simonmlewis »

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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Wordpress Pagination Links - how do I modify this?

Post by Celauran »

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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Wordpress Pagination Links - how do I modify this?

Post by Celauran »

simonmlewis wrote:This is the entire "single-product-reviews.php" file:

Code: Select all

<?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/template-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:

Code: Select all

<?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>
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Wordpress Pagination Links - how do I modify this?

Post by simonmlewis »

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.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Wordpress Pagination Links - how do I modify this?

Post by simonmlewis »

My bad - <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> is what I added, not <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>.

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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Wordpress Pagination Links - how do I modify this?

Post by Celauran »

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?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Wordpress Pagination Links - how do I modify this?

Post by simonmlewis »

It starts here:

Code: Select all

                        <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):

Code: Select all

/**
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'] = user_<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>(user_<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 user_<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> (shows as smurf on here... the trailing stuff.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Wordpress Pagination Links - how do I modify this?

Post by Celauran »

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.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Wordpress Pagination Links - how do I modify this?

Post by simonmlewis »

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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Wordpress Pagination Links - how do I modify this?

Post by Celauran »

You can pass that in as an argument to get_comments
Post Reply