All pastes #69044 Raw Edit

headzoo

public php v1 · immutable
#69044 ·published 2006-06-22 13:11 UTC
rendered paste body
<?php/** Plugin Name: Sean's Recent Posts Plugin URI: http://www.headzoo.com Version: 1.0 Author: Sean Hickey Author URI: http://www.headzoo.com Description: Umm.. Recent posts or something.*/add_action('seans_recent_posts', 'seans_recent_posts', 10, 2);function seans_recent_posts($limit = 5, $excerptLength = 55) {	global $wpdb;	$results = $wpdb->get_results("SELECT ID, post_title, post_content, comment_count FROM `$wpdb->posts` WHERE `post_status` = 'publish' ORDER BY `post_date` DESC LIMIT $limit", ARRAY_A);	if (empty($results)) {		return;	}		foreach ($results as $result) {		$postID = $result['ID'];		$excerpt = seans_excerpt($result['post_content'], $excerptLength);		$postTitle = $result['post_title'];		$permalink = get_permalink($postID);		$comments = $result['comment_count'];				?>		<div class="recent_posts">			<p class="recent_posts_title"><a href="<?php echo $permalink; ?>" title="<?php echo htmlspecialchars($postTitle, ENT_QUOTES); ?>"><?php echo $postTitle; ?></a></p>			<p class="recent_posts_excerpt"><?php echo $excerpt; ?></p>			<p class="recnet_posts_comments">Comments [<?php echo $comments; ?>]</p>		</div>		<?php	}}function seans_excerpt($text, $length) {		$text = apply_filters('the_content', $text);		$text = str_replace(']]>', ']]&gt;', $text);		$text = strip_tags($text);		$excerpt_length = $length;		$words = explode(' ', $text, $excerpt_length + 1);		if (count($words) > $excerpt_length) {			array_pop($words);			array_push($words, '[...]');			$text = implode(' ', $words);		}	return $text;}?>