Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have implemented custom code for generating comments on post page using callback function in functions.php.

function MYTHEME_comment($comment, $args, $depth) {
   $GLOBALS['comment'] = $comment; ?>

<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
   <div class="comment-author vcard">
     <?php echo get_avatar($comment,$size='48' ); ?>
       <div class="comment-meta"><a href="<?php the_author_meta( 'user_url'); ?>"><?php printf(__('%s'), get_comment_author_link()) ?></a></div>
     </div>
     <div class="clear"></div>

     <?php if ($comment->comment_approved == '0') : ?>
       <em><?php _e('Your comment is awaiting moderation.') ?></em>
       <br />
     <?php endif; ?>

     <div class="comment-text"> 
         <?php comment_text() ?>
     </div>

   <div class="reply">
      <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
       <span class="comment-date"> <?php printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?><?php edit_comment_link(__('(Edit)'),'  ','') ?></span>
   </div>

Here is a pastebin of the same code http://pastebin.com/nUjvsFua

It generates basic code to show all the comments on that post. I want the first five comments to be shown and then a "View more" button to show remaining comments. Any guide on how can I achieve this?

share|improve this question
    
That code only displays one comment, you have to loop it 5 times then show a read more link. –  Nicholas Pickering Feb 22 '13 at 18:41
    
That function is called by wordpress for each comment. Iis is called by wp_list_comments( array( 'callback' => 'MYTHEME_comment' ) ) –  rockvilla Feb 22 '13 at 18:46
add comment

1 Answer 1

Set per_page to 5 and page to 1 in wp_list_comments

http://codex.wordpress.org/Function_Reference/wp_list_comments

Then add your read more link just below your comments to reload the page with per_page and page not set. You can do this with AJAX for smoothness.

share|improve this answer
    
It is working partially. setting per_page to '5' and page to '1', it displays oldest 5 comments but I want to show newest 5 comments. Setting reverse_top_level to true or false also doesn't help. /any idea how can I go about this? –  rockvilla Feb 23 '13 at 8:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.