WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. CherryHintonBlue
    Member
    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'); ?>
    	<?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>
  2. vtxyzzy
    Member
    Posted 1 year ago #

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

  3. CherryHintonBlue
    Member
    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

Tags

No tags yet.