get_post_thumbnail_id()

最后更新于:2021-11-26 22:41:19

get_post_thumbnail_id( int|GC_Post$post=null)

Retrieve post thumbnail ID.

参数

$post

(int|GC_Post) (Optional) Post ID or GC_Post object. Default is global $post.

Default value: null

响应

(int|false) Post thumbnail ID (which can be 0 if the thumbnail is not set), or false if the post does not exist.

源文件

文件: gc-includes/post-thumbnail-template.php

function get_post_thumbnail_id( $post = null ) {
	$post = get_post( $post );

	if ( ! $post ) {
		return false;
	}

	return (int) get_post_meta( $post->ID, '_thumbnail_id', true );
}
$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 );
	}
}