Re: WPのギャラリーからの画像取得について
永らくありがとうございました › フォーラム › テーマ › WPのギャラリーからの画像取得について › Re: WPのギャラリーからの画像取得について
2011 年 10 月 27 日 3:06 AM
#3304
キーマスター
http://www.white-room.jp/blog/?m=200904
のコードを見る限り、
<code><?php get_the_post_image(get_the_ID(), 'thumbnail', 10, 1); ?></code>
では、表示が行われません。
function get_the_post_image($postid,$size,$order=0,$max=null)は
- この関数ではecho していませんので、
<code><?php echo get_the_post_image(...); ?></code>
として利用しなければなりません。
- $orderは ギャラリーの1番目が0となりますので、10番目の場合は、9とする必要があります。
- $maxは$orderより大きな数字あるいは、無指定でないと表示が行われません。
というか、forループの中で、returnしてますので、そもそも、1画像しか表示出来ません。
このあたり、作者様の意図を充分理解できていないのであれなのですが、そりあえず画像が1個だけとして
<code><?php echo get_the_post_image(get_the_ID(), 'thumbnail', 9); ?></code>
といった使い方で、よいのではないでしょうか。
ちなみに、指定数の画像を得たい場合のget_the_post_image()の修正例を示しておきます。
<code>function get_the_post_image($postid,$size='full',$offset=0,$numberimages=-1) {<br /> $args = array(<br /> 'post_type' => 'attachment',<br /> 'post_mime_type' => 'image',<br /> 'orderby' => 'menu_order',<br /> 'order' => 'ASC',<br /> 'post_status' => null,<br /> 'numberposts' => $numberimages,<br /> 'offset' => $offset,<br /> 'post_parent' => $postid,<br /> );<br /> <br /> $attachments = get_posts( $args );<br /> if ( $attachments ) {<br /> foreach ( $attachments as $attachment ) {<br /> echo '<li>';<br /> echo wp_get_attachment_image( $attachment->ID, $size );<br /> echo '</li>';<br /> }<br /> }<br /> }</code>
こちらではechoしてるので、
<code><?php get_the_post_image(get_the_ID(), 'thumbnail', 9, 1); ?></code>
のような使い方になります。
# XPressMEではなく、WordPressを使ったテストでの質問でも、出来る限りの回答はさせていただきますが、回答が遅くなったり、解決できない場合もありますので、
http://ja.forums.wordpress.org/ ほうが回答率がよいと思います。
あるいは、作者さまへの問い合わせとか