- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
関数リファレンス/get post galleries images
提供: WordPress Codex 日本語版
Description
Retrieves an array of image URLs that belong to galleries added to the specified post.
Parameters
- $post
- (Post ID or object.) (必須) The post to look in.
- 初期値: なし
Return
- (array)
- A multidimensional array of image URLs.
Usage
%%% <?php $galleries = get_post_galleries_images( $post ); ?> %%%
Example
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; // Only do this on singular items if( ! is_singular() ) return $content; // Make sure the post has a gallery in it if( ! has_shortcode( $post->post_content, 'gallery' ) ) return $content; // Retrieve all galleries of this post $galleries = get_post_galleries_images( $post ); $image_list = '<ul>'; // Loop through all galleries found foreach( $galleries as $gallery ) { // Loop through each image in each gallery foreach( $gallery as $image ) { $image_list .= '<li>' . $image . '</li>'; } } $image_list .= '</ul>'; // Append our image list to the content of our post $content .= $image_list; return $content; } add_filter( 'the_content', 'pw_show_gallery_image_urls' );
Change Log
- Since: 3.6.0
Source File
get_post_gallery_images() is located in wp-includes/media.php
.
Related
get_post_galleries() get_post_gallery_images()
この記事は翻訳時に編集が必要であるとマークされていました。その為Codex原文が大きく編集されている可能性があります。内容を確認される際は原文を参照していただき、可能であれば本項目へ反映させてください。よりよいCodexを作成するためのお手伝いをお願いします。