Languages: English • Italiano • 日本語 (Add your language)
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.
<?php $post_thumbnail_id = get_post_thumbnail_id( $post_id ); ?>
To get all post attachments except the Featured Image, 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' => 'any', '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 ); } } ?>
Since: 4.4.0 $post can be a post ID or WP_Post object.
Since: 2.9.0
get_post_thumbnail_id() is located in wp-includes/post-thumbnail-template.php
.