All pastes #66903 Raw Edit

headzoo

public text v1 · immutable
#66903 ·published 2006-06-18 19:13 UTC
rendered paste body
<?php
/*
Plugin Name: Sean's Comments
Plugin URI: http://www.headzoo.com
Description: Show latest comments and a piece of the comment...
Author: Sean Hickey
Version: 1.0
Author URI: http://www.headzoo.com
*/

function scomments($num = 10, $length = 90, $before = '<li>', $after = '</li>', $dateFormat = 'Y m-d') {
	global $wpdb;
	$comments = $wpdb->get_results("SELECT comment_author, comment_ID, comment_post_ID, comment_content, comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $num");
	
	$html = "<ul class='seans_comments'>\r\n";
	foreach ($comments as $comment) {
		$html .= $before;
		$commentDate = strtotime($comment->comment_date);
		$commentDate = date($dateFormat, $commentDate);
		$html .= '<p><a href="' . get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">';
		$html .= get_the_title($comment->comment_post_ID);
		$html .= '</a></p>';
		$html .= '<p>by <i>' . $comment->comment_author . '</i> on ' . $commentDate . '</p>';
		$html .= '<p>' . nl2br(chopString($comment->comment_content, $length)) . '</p>';
		$html .= $after;
	}
	$html .= "</ul>\r\n";
	
	echo $html;
}

function chopString($string, $length) {
	$string = strip_tags($string);
	if (strlen($string) > $length) {
		$string = substr($string, 0, $length) . '[...]';
	}
	return $string;
}
?>