All pastes #66268 Raw Edit

headzoo

public text v1 · immutable
#66268 ·published 2006-06-16 18:34 UTC
rendered paste body
<?php
/**
 * Plugin Name: Teaser Image
 * Plugin URI: http://www.headzoo.com
 * Version: 1.0
 * Description: Teaser image for posts
 * Author: Sean Hickey
 * Author URI: http://www.headzoo.com
 */

add_action('the_teaser_image', 'tsr_theImage');
function tsr_theImage($defaultImage = null, $id = null) {
	global $post, $wpdb;
	
	if ($id) {
		$postID = $id;
	} else {
		$postID = $post->ID;
	}
	
	$image = $wpdb->get_var("SELECT guid FROM $wpdb->posts WHERE post_parent = $postID AND post_title LIKE '%tsr-%' LIMIT 1");
	if (empty($image)) {
		if (empty($defaultImage)) {
			return;
		}
		$image = $defaultImage;
	}
	$permalink = get_permalink($postID);
	echo "<a href=\"$permalink\" title=\"$post->post_title\" class=\"teaser-link\"><img src=\"$image\" alt=\"$post->post_title\" class=\"teaser-img\" /></a>";
}

?>