1096 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Beta Tester
  • Collector Level 2
+5 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

3439 posts
  • Author Level 4
  • Collector Level 2
  • Community Superstar
  • United States
+2 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; ?>
709 posts
  • Affiliate Level 2
  • Author Level 5
  • Beta Tester
  • Collector Level 2
+2 more
ChillThemes
says

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

paginate_links() are not for comments.

1096 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Beta Tester
  • Collector Level 2
+5 more
Gareth_Gillman
says

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

1096 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Beta Tester
  • Collector Level 2
+5 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
  • Author Level 5
  • Collector Level 1
  • 2 Years of Membership
  • Exclusive Author
themebros
says

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

1096 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Beta Tester
  • Collector Level 2
+5 more
Gareth_Gillman
says

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

by
by
by
by
by
by