Below is a function that displays the latest 4 approved comments on my homepage, I wrote this almost a year ago, and for the life of me, it’s gone completely from my head, All i want to do is add a permalink to where the comment is located. How do I, and where do I add this?
function showLatestComments() {
global $wpdb;
$sql = "
SELECT DISTINCT comment_post_ID, comment_author, comment_date_gmt, comment_approved, SUBSTRING(comment_content,1,100) AS com_excerpt
FROM $wpdb->comments
WHERE comment_approved = '1'
ORDER BY comment_date_gmt DESC
LIMIT 4";
$comments = $wpdb->get_results($sql);
$output .= '<img src="/wp-content/themes/blue-and-grey/images/student-perspectives.jpg" /><h2>Latest student perspectives</h2>
<ul id="comm">';
foreach ($comments as $comment) {
$output .= '<li><strong>'. $comment->comment_author . ' said</strong> : "' . strip_tags($comment->com_excerpt). '..."</li>';
}
$output .= '</ul>';
echo $output;
}
//end function
Make use of the
get_comment_link
function in yourforeach
loop like so: