Codex

Function Reference/get post thumbnail id

Contents

Description

  1. If a thumbnail is set - Returns the ID of the Thumbnail attached to the post
  2. If no such attachment exists, the function returns null (Empty value)

Note: To enable post thumbnails, the current theme must include add_theme_support( 'post-thumbnails' ); in its functions.php file. See also Post Thumbnails.

Synopsis

(int) $id = get_post_thumbnail_id();

Usage

 <?php  $post_thumbnail_id get_post_thumbnail_id$post_id ); ?> 

Parameters

post_id
(integer) (Optional) Post ID.
Default: None

Examples

Show All attachments for the current post beside Thumb

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 );
	}
}

?>

Source File

get_post_thumbnail_id() is located in wp-includes/post-thumbnail-template.php.

Related

Post Thumbnails: has_post_thumbnail(), the_post_thumbnail(), get_post_thumbnail_id(), get_the_post_thumbnail(), add_image_size(), set_post_thumbnail_size()

See also index of Function Reference and index of Template Tags.