get_post_thumbnail_id

Sponsored Link
  1. サムネイルが設定されている場合 – 記事に添付されているサムネイルIDを返します。
  2. 添付ファイルが存在しない場合、関数はnull を返します(空の値)。

Sponsored Link

  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)

注意:post thumbnailsを有効にするためには、現在のテーマのfunctions.phpファイルにadd_theme_support( ‘post-thumbnails’ );を含めなければなりません。Post Thumbnailsを参照してください。

Note: To enable 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();

get_post_thumbnail_idのテンプレートタグ使用方法

<?php  $id = get_post_thumbnail_id(); ?> 

get_posts()のようなものでこの関数を使用する事ができるサムネイル横の全ての添付ファイルを取得します。

To get all attacments beside the thumb you can use this function with something like get_posts().

サムネイル横に現在の記事の全ての添付ファイルを表示する方法

The_Loop内部でします($post->IDが使用可能です)。

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

?>
Sponsored Link