From 77749a6009b131dd377e66b680bace06fedcd37f Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Sat, 10 Oct 2009 08:31:21 +0000 Subject: [PATCH] First pass at canonical post image template functions. see #10928 git-svn-id: https://develop.svn.wordpress.org/trunk@12019 602fd350-edb4-49c9-b593-d223f7449a82 --- 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 f7a5a5bcaf..066a9c4ac4 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 //