WORDPRESS – GET AND DISPLAY MOST RECENT COMMENT ON EVERY POST

0 51

 

PHP Code:

Use this code inside the loop to display comment on every post.

get_comments() funtions

Retrieve a list of comments.

Syntax

Parameters

  • status: Comment status to return.
    • hold
    • approve
    • spam
    • trash
  • orderby: Comment field used to sort comments.
  • order: How to sort $orderby.
    • ASC
    • DESC
  • number: Number of comments to return. Leave blank to return all comments.
  • offset: Offset from latest comment. You must include $number along with this.
  • post_id: Only return comments for a particular post or page.

The codes above only display latest single comment on every post, to add comment count, simply add this line of code.

comments_number() funtions

Displays the total number of comments, Trackbacks, and Pingbacks for the current post. This tag must be within The Loop.

Syntax

Parameters

  • zero: Text to display when there are no comments.
  • one: Text to display when there is one comment.
  • more: Text to display when there is more than one comment.

So now it displays the latest comment on every post with comment count and add comment link on it, if you wish to add CSS code in comment count display, use the complete code below.

Happy blogging. 🙂

You might also like More from author

Leave A Reply

Your email address will not be published.