Support » Fixing WordPress » Determining the date of the most recent comment

  • 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'); ?>
    	<?php
    	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>' ;
    	}
    	else
    	{
    		echo 'Be the first to comment!';
    	}
    	?>
    	</div>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Determining the date of the most recent comment’ is closed to new replies.