I'm getting 5 recent comments into my sidebar using the following code:
<?php $recent_comments = get_comments('status=approve&number=5'); ?>
<?php foreach ($recent_comments as $comment) { ?>
<li>
<a href="#"><?php echo get_avatar( $comment, '60' ); ?> </a>
<div>
<a href="<?php echo get_permalink($comment->ID); ?>" title="on <?php echo $comment->post_title; ?>"><?php echo strip_tags($comment->comment_author); ?> </a><br />
<span><?php echo wp_html_excerpt( $comment->comment_content, 35 ); ?>...</span>
</div>
</li>
<?php } ?>
But the problem that I am facing is: When I click on the comment link it's redirecting me to the current page instead of the page that is commented. On other hand, when I click on the comment link (that is in sidebar) in homepage, it's redirecting me to the latest post page.
I have used wp_reset_query()
but the problem persists.
Also usingt get_comment($comment->ID);
instead of get_permalink
is not working.