From 831178162c74a20d44f435d4dd8ef6d68a9d16f8 Mon Sep 17 00:00:00 2001 From: markjaquith Date: Sat, 10 Oct 2009 08:31:21 +0000 Subject: [PATCH] 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 --- wp-includes/post-template.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index f7a5a5bca..066a9c4ac 100644 --- a/wp-includes/post-template.php +++ b/wp-includes/post-template.php @@ -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 //