Skip to content

Instantly share code, notes, and snippets.

@leocaseiro
Created January 23, 2015 05:29
Show Gist options
  • Save leocaseiro/d01349cd0282cf164c1f to your computer and use it in GitHub Desktop.
Save leocaseiro/d01349cd0282cf164c1f to your computer and use it in GitHub Desktop.
Comments Pagination WordPress
<?php
$comments_per_page = 2;
$page = 2;
//MYSQL: LIMIT offset, number
$params = array(
'post_id' => $post_id,
'offset' => (--$page) * $comments_per_page,
'number' => $comments_per_page,
);
$comments = get_comments( $params );
$total_comments = get_comments(
array_merge($params,
array(
'count' => true,
'offset' => 0,
'number' => 0
)
)
);
$args = array(
'total' => $total_comments,
'current' => max( 1, $page ),
);
$pagination = paginate_links( $args );
foreach ( $comments as $comment ) :
echo $comment->comment_date;
echo $comment->comment_author;
echo $comment->comment_content;
endforeach;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment