- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
関数リファレンス/get post gallery images
提供: WordPress Codex 日本語版
投稿に追加された1つまたは複数のギャラリーのうち、最初のギャラリーにある画像の URL を配列として読み出す関数です。
パラメータ
- $post
- (投稿 ID またはオブジェクト) (必須) ギャラリーのある投稿。
- 初期値: なし
戻り値
- (array)
- 画像URLの多次元配列
使用法
<?php $gallery = get_post_gallery_images( $post ); ?>
使用例
A simple example of how to append the raw image URLs to the content of any post or page that has at least one gallery.
function pw_show_gallery_image_urls( $content ) { global $post; // is_single()、is_page() 、is_attachment() いづれかのシングルページに対してのみ実行。 if( ! is_singular() ) return $content; // 投稿にギャラリーが載っていることを確認。 if( ! has_shortcode( $post->post_content, 'gallery' ) ) return $content; // 投稿にある最初の投稿を読み出す。 $gallery = get_post_gallery_images( $post ); $image_list = '<ul>'; // ギャラリーの各イメージに対してループを実行 foreach( $gallery as $image ) { $image_list .= '<li>' . $image . '</li>'; } $image_list .= '</ul>'; // 投稿に画像リストを挿入 $content .= $image_list; return $content; } add_filter( 'the_content', 'pw_show_gallery_image_urls' );
改訂履歴
- 3.6.0 にて導入されました。
ソースファイル
get_post_gallery_images() は wp-includes/media.php
にあります。
関連項目
get_post_galleries(), get_post_galleries_images()
最新英語版: WordPress Codex » Function Reference/get post gallery images (最新版との差分)
この記事は翻訳時に編集が必要であるとマークされていました。その為Codex原文が大きく編集されている可能性があります。内容を確認される際は原文を参照していただき、可能であれば本項目へ反映させてください。よりよいCodexを作成するためのお手伝いをお願いします。