454 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Microlancer Beta Tester
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

I am having issues with the comment pagination, the code below throws an error:

Fatal error: Can’t use function return value in write context in /home/monthlyw/public_html/comments.php on line 30
Line 30 is the one beginning >>
<?php
global $wp_query;
$total = $wp_query->max_num_pages;
// only bother with the rest if we have more than 1 page!
if ( $total > 1 )  {
     // get the current page
     if ( !$current_page = get_query_var('paged') )
          $current_page = 1;
     // structure of "format" depends on whether we're using pretty permalinks
>>     $format = empty( get_option('permalink_structure') ) ? '&page=%#%' : 'page/%#%/';
     echo paginate_links(array(
          'base' => get_pagenum_link(1) . '%_%',
          'format' => $format,
          'current' => $current_page,
          'total' => $total,
          'mid_size' => 4,
          'type' => 'list'
     ));
}
?>

Any help as the codex is a little bare on comment pagination, and Google doesn’t throw up many tuts for the pagination.

I would like my pagination to look the same as my pages pagination which you can see here

3113 posts
  • Sold between 5 000 and 10 000 dollars
  • United States
  • Bought between 10 and 49 items
  • Has been a member for 3-4 years
  • Exclusive Author
chrisakelley says
<?php paginate_comments_links(); ?> 
http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/link-template.php#L1806

EDIT: lets prevent errors

        <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :  ?>

        <nav class="pagination">

            <?php paginate_comments_links(); ?> 

          </nav>

        <?php endif; ?>
707 posts
  • Sold between 10 000 and 50 000 dollars
  • Referred between 10 and 49 users
  • Bought between 10 and 49 items
  • Has been a member for 5-6 years
  • Exclusive Author
  • Microlancer Beta Tester
ChillThemes says

What OrganicBeeMedia said, use http://codex.wordpress.org/Template_Tags/paginate_comments_links

paginate_links() are not for comments.

454 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Microlancer Beta Tester
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

Thanks guys, my first time creating comment pagination so on a little learning spree :)

454 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Microlancer Beta Tester
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

Been modifying the code to my needs but somehow, WP is showing the comments from another post on all the posts.

See here, the meta info says no comments (and shows in the admin area) but comments are being shown:

My code is:
$comments = get_comments($args, $post->ID);
foreach($comments as $comment) :

 echo '<div class="comment margin30"><div class="avatar">';
 echo get_avatar( $comment, 32 );
 echo '</div><div class="comm-text-wrap"><div class="comm-text"><p style="font-family: Verdana;">';
 echo($comment->comment_author);
 echo '</p><div class="bubble"><div class="bubble-bg" /><p>';
 echo($comment->comment_content);
 echo comment_reply_link( $comment );
 echo '</p></div></div></div></div>';

endforeach;
unset($comments);

$num_comments = get_comments_number();

if ( comments_open() ) {
 if ( $num_comments == 0 ) {
  $comments = __('No Comments', 'your_text_domain');
 } elseif ( $num_comments > 1 ) {
  echo '<div class="pagination">';
  paginate_comments_links(); 
  echo '</div>';
 }
}

echoing $num_comments gives me the total of 0 comments

Any help is appreciated

161 posts
  • Bought between 1 and 9 items
  • Europe
  • Has been a member for 1-2 years
  • Sold between 10 000 and 50 000 dollars
  • Exclusive Author
themebros says

Add wp_reset_query(); on top of that code you pasted.

454 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Microlancer Beta Tester
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

All sorted, rewrote the comment function and found the error, now works a charm :)

by
by
by
by
by
by