Codex tools: Log in
Contents |
Note: To enable featured images, see post thumbnails, the current theme must include add_theme_support( 'post-thumbnails' ); in its functions.php file. See also Post Thumbnails.
(int) $id = get_post_thumbnail_id();
<?php $post_thumbnail_id = get_post_thumbnail_id( $post_id ); ?>
To get all attachments beside the thumb you can use this function with something like get_posts().
Do this inside The_Loop (where $post->ID is available).
<?php $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID, 'exclude' => get_post_thumbnail_id() ); $attachments = get_posts( $args ); if ( $attachments ) { foreach ( $attachments as $attachment ) { echo apply_filters( 'the_title', $attachment->post_title ); the_attachment_link( $attachment->ID, false ); } } ?>
"Post Thumbnail" is an outdated term for "Featured Image". This function returns the ID of the post's featured image. It does not return IDs of other images attached to posts that are thumbnail sized.
get_post_thumbnail_id() is located in wp-includes/post-thumbnail-template.php.
Post Thumbnails: has_post_thumbnail(), the_post_thumbnail(), get_post_thumbnail_id(), get_the_post_thumbnail(), add_image_size(), set_post_thumbnail_size()