Ready to get started?Download WordPress


Determining the date of the most recent comment (3 posts)

  1. CherryHintonBlue
    Posted 1 year ago #

    I have some pages which have a lot of comments, and I want to put a link at the top which will take people to the last comment on the page ...but what I'd like to do is to show the date of that comment too. The code below works on posts, but not pages. Any ideas how to make it work on pages would be most welcome. Thanks!

    <div class="commentskip">
    	<?php $comment_date = $wpdb->get_results('SELECT DATE_FORMAT(comment_date, "%D %M %Y") as comment_date FROM wp_comments WHERE comment_post_ID = '.get_the_ID().' ORDER BY comment_ID DESC LIMIT 1'); ?>
    	if (isset($comment_date[0]->comment_date))
    		echo '<p><a href="#lastcomment">Skip to the most recent comment</a>: (' . $comment_date[0]->comment_date . ')</p>' ;
    		echo 'Be the first to comment!';
  2. vtxyzzy
    Posted 1 year ago #

    Is this code 'in the Loop'? If so, try using $post->ID instead of get_the_id().

  3. CherryHintonBlue
    Posted 1 year ago #

    Thanks vtxyzzy - I'll give that a go.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.