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

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 »

Wow what a job there. The difficulty I have is in comments.php, I have this:

Code: Select all

			<ul>
			<?php 
                $comments = get_comments(['post_id' => get_the_ID()]);
                $comments = array_filter($comments, function($comment) {
                    return !empty($comment->comment_content);
                });
                
                        wp_list_comments( 'type=comment&callback=blade_grve_comments', $comments); ?>
			</ul>
So not an "ol", tho that's just semantics, but not the rest of the stuff in that tag either.
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 »

It also doesn't like starting in the function...

Code: Select all

$defaults['base'] = <span style='color:blue'
The <span. that first < is not liked.

[text]Parse error: syntax error, unexpected '<' in /var/www/vhosts/staging.site.co.uk/httpdocs/wp-content/themes/blade-child/functions.php on line 202
[/text]
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 think that's something that got mangled by the forum software, and I can't seem to post it. That line should be the same as in the original paginate_comments_links function.
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 »

can you send me a screenshot of what it should be please? I guess there are double quotes in there?
I can see you have added smurf stuff for fun. Which I guess is to be replaced with 1, 2... etc.
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 »

That's not me having a laugh, that's the forum software filtering out what it thinks is either spam or malicious code. Can't upload a screenshot for some reason, so here's a link: https://imgur.com/gFNIUpG
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 wow yes I see.

so I added it, and no errors now, but the pagination still appears.
This is the actual code is generates around each number:

Code: Select all

<nav class="woocommerce-pagination"><ul class='page-numbers'>
	<li><span class='page-numbers current'>1</span></li>
	<li><a class='page-numbers' href='http://staging.site.co.uk/product/red-shirt/comment-page-2/#comments'>2</a></li>
	<li><a class='page-numbers' href='http://staging.site.co.uk/product/red-shirt/comment-page-3/#comments'>3</a></li>
	<li><span class="page-numbers dots">&hellip;</span></li>
	<li><a class='page-numbers' href='http://staging.site.co.uk/product/red-shirt/comment-page-10/#comments'>10</a></li>
	<li><a class="next page-numbers" href="http://staging.site.co.uk/product/red-shirt/comment-page-2/#comments">&rarr;</a></li>
</ul>
</nav>
It's doing this when there are no comments (with content).
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 »

The pagination should presumably still appear, just the number of pages should be reduced to the correct amount. I took a fresh install of WordPress, added 400 comments, some with content, some without, and the code I listed now shows 11 pages (20 comments per page) instead of 21, which would be the norm. Does that not line up with what you're seeing? (With adjusted numbers, obviously)
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 »

In theory this page should show NO page numbers at all
There are 272 star ratings (no comment text) comments. So the Reviews themselves are empty. But shows the pagination.
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 »

Interesting... Have you inspected the $comments array? Does it contain anything?
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's probably worth saying too that in the view source is has <ul class='page-numbers'> but in comments.php it doesn't have that.
And if I add "<ul class='fred'>", it doesnt render 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 »

simonmlewis wrote:It's probably worth saying too that in the view source is has <ul class='page-numbers'> but in comments.php it doesn't have that.
That is useful. Tells us this isn't being rendered by comments.php, but some other file. See if you can track down where these comments are being generated from and we can work from there. Time for me to go to work now, so I probably won't be able to look at this again until tonight.
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 »

Will do - leave it with me.
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 »

Found the file. IT's in out child theme for single-product-reviews.php.

This is the HTML part:

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' ) ) ); ?>
			</ol>
I tried this but it kept the page number and moved it under comments:

Code: Select all

			<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',$comments, array( 'callback' => 'woocommerce_comments', 'end-callback' => 'jbbg_woocommerce_comments_end',  ) ) ); ?>
			</ol>
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 you've added $comments to the wrong place in the wp_list_comments call. It needs to be the second argument, so right before the last closing parenthesis. Don't forget you'll also need to swap out calls to pagination methods for the new ones.
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 »

Do you mean to add $comments before the final ) ?
What do you mean about swapping out calls ??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply