First pass at canonical post image template functions. see #10928

git-svn-id: http://svn.automattic.com/wordpress/trunk@12019 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
markjaquith 2009-10-10 08:31:21 +00:00
parent a0cd792aae
commit 831178162c
1 changed files with 35 additions and 0 deletions

View File

@ -893,6 +893,41 @@ function walk_page_dropdown_tree() {
return call_user_func_array(array(&$walker, 'walk'), $args);
}
//
// Post images
//
function has_post_image( $post_id = NULL ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
return !! get_post_image_id( $post_id );
}
function get_post_image_id( $post_id = NULL ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
return get_post_meta( $post_id, '_thumbnail_id', true );
}
function the_post_image( $size = 'thumbnail' ) {
echo get_the_post_image( $size );
}
function get_the_post_image( $size = 'thumbnail', $post_id = NULL ) {
global $id;
$post_id = ( NULL === $post_id ) ? $id : $post_id;
$post_image_id = get_post_image_id( $post_id );
$size = apply_filters( 'post_image_size', $size );
if ( $post_image_id ) {
do_action( 'begin_fetch_post_image_html', $post_id, $post_image_id, $size ); // for "Just In Time" filtering of all of wp_get_attachment_image()'s filters
$html = wp_get_attachment_image( $post_image_id, $size );
do_action( 'end_fetch_post_image_html', $post_id, $post_image_id, $size );
} else {
$html = '';
}
return apply_filters( 'post_image_html', $html, $post_id, $post_image_id );
}
//
// Attachments
//