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.

let's say I have posts with hundreds of comments, and that I want to show only the last N comments and then a link to a page read them all. How would I display the last N comments?

Thank you, Dino.

share|improve this question
1  
Where do you need this, on which page? Of the concrete post? –  hakre Dec 20 '10 at 17:10

2 Answers 2

See.
http://codex.wordpress.org/Function_Reference/get_comments

Set the orderby parameter to your desired value, possible values are.

comment_agent
comment_approved
comment_author
comment_author_email
comment_author_IP
comment_author_url
comment_content
comment_date
comment_date_gmt
comment_ID
comment_karma
comment_parent
comment_post_ID
comment_type
user_id

Refer to the link already provided for info on setting other parameters, and general examples.

share|improve this answer
    
Note that you need to replace the comments_template() with this, otherwise WP will still query the database for those hundreds of comments. To display all the comments on a separate page call the current page with a query argument like ?show_all_comments. Get all the comments form the db if this argument is present, otherwise get only 10 or something like that –  onetrickpony Dec 19 '10 at 11:16
    
here's a similar thread which should help you do what you want: wordpress.stackexchange.com/questions/5358/… (you'll need that sql query for all the comments part) –  onetrickpony Dec 19 '10 at 11:19
    
Why would you need a direct SQL query to fetch comments in this instance, this makes absolutely no sense to me at all. The user asked for a method for pulling comments, not specific to any kind of post or page, what relevance does the comment template have here? Curious for some clarification on your points. –  t31os Dec 19 '10 at 11:41
    
ok I'll post the entire code in a new answer, it's easier to understand –  onetrickpony Dec 19 '10 at 11:48
    
Look forward to it... :) –  t31os Dec 19 '10 at 11:51

Why not just use native functionality for comment pagination?

See Enhanced Comment Display, Settings > Discussion in Codex.

share|improve this answer

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.