760 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
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

3344 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee 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
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+2 more
ChillThemes says

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

paginate_links() are not for comments.

760 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
Gareth_Gillman says

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

760 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
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
  • Has sold $10,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Located in Europe
  • Has been part of the Envato Community for over 1 year
+1 more
themebros says

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

760 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
Gareth_Gillman says

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

by
by
by
by
by
by