- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
「関数リファレンス/get post gallery images」の版間の差分
提供: WordPress Codex 日本語版
< 関数リファレンス
(英語版をコピペ。) |
(和訳完了。) |
||
1行目: | 1行目: | ||
− | = | + | <div id="Description"> |
+ | == 説明 == | ||
+ | </div> | ||
+ | 投稿に追加された1つまたは複数のギャラリーのうち、最初のギャラリーにある画像の URL を配列として読み出す関数です。 | ||
− | + | <div id="Parameters"> | |
+ | == パラメータ == | ||
+ | </div> | ||
+ | {{Parameter|$post|投稿 ID またはオブジェクト|ギャラリーのある投稿。}} | ||
− | == | + | <div id="Return"> |
− | {{ | + | == 戻り値 == |
+ | </div> | ||
+ | {{Return||array|画像URLの多次元配列}} | ||
− | == | + | <div id="Usage"> |
− | + | == 使用法 == | |
+ | </div> | ||
+ | <?php $gallery = get_post_gallery_images( $post ); ?> | ||
− | + | <div id="Example"> | |
− | + | == 使用例 == | |
− | + | </div> | |
− | == | + | |
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. | 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. | ||
<pre> | <pre> | ||
19行目: | 28行目: | ||
global $post; | global $post; | ||
− | // | + | // is_single()、is_page() 、is_attachment() いづれかのシングルページに対してのみ実行。 |
if( ! is_singular() ) | if( ! is_singular() ) | ||
return $content; | return $content; | ||
− | // | + | // 投稿にギャラリーが載っていることを確認。 |
if( ! has_shortcode( $post->post_content, 'gallery' ) ) | if( ! has_shortcode( $post->post_content, 'gallery' ) ) | ||
return $content; | return $content; | ||
− | + | // 投稿にある最初の投稿を読み出す。 | |
− | $ | + | $gallery = get_post_gallery_images( $post ); |
$image_list = '<ul>'; | $image_list = '<ul>'; | ||
− | // | + | // ギャラリーの各イメージに対してループを実行 |
foreach( $gallery as $image ) { | foreach( $gallery as $image ) { | ||
41行目: | 50行目: | ||
$image_list .= '</ul>'; | $image_list .= '</ul>'; | ||
− | // | + | // 投稿に画像リストを挿入 |
$content .= $image_list; | $content .= $image_list; | ||
50行目: | 59行目: | ||
</pre> | </pre> | ||
− | = | + | <div id="Change Log"> |
− | * | + | == 改訂履歴 == |
+ | </div> | ||
+ | * [[Version 3.6|3.6.0]] にて導入されました。 | ||
− | = | + | <div id="Source File"> |
+ | == ソースファイル == | ||
+ | </div> | ||
<!-- Need links to current source code files --> | <!-- Need links to current source code files --> | ||
− | <tt>get_post_gallery_images()</tt> | + | <tt>get_post_gallery_images()</tt> は {{Trac|wp-includes/media.php}} にあります。 |
− | = | + | <div id="Related"> |
+ | == 関連項目 == | ||
+ | </div> | ||
+ | [[Function_Reference/get_post_galleries|get_post_galleries()]], [[Function_Reference/get_post_galleries_images|get_post_galleries_images()]] | ||
− | + | {{原文|Function Reference/get post gallery images|134442}}<!-- 22:12, 12 August 2013 Djkaz 版 --> | |
− | + | ||
[[Category:Functions]] | [[Category:Functions]] | ||
{{Copyedit}} | {{Copyedit}} |
2013年8月13日 (火) 07:16時点における版
投稿に追加された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を作成するためのお手伝いをお願いします。