Re: WPのギャラリーからの画像取得について
永らくありがとうございました › フォーラム › テーマ › WPのギャラリーからの画像取得について › Re: WPのギャラリーからの画像取得について
2011 年 10 月 28 日 12:10 AM
#3306
キーマスター
なるほど、ギャラリーの画像順序番号(menu_order)指定での抽出ということであれば、
<code>function get_image_by_menu_order($postid,$menu_order=1,$size='full') {<br /> $args = array(<br /> 'post_type' => 'attachment',<br /> 'post_mime_type' => 'image',<br /> 'post_status' => null,<br /> 'post_parent' => $postid<br /> );<br /> $attachments = get_posts( $args );<br /> if ( $attachments ) {<br /> foreach ( $attachments as $attachment ) {<br /> if ($attachment->menu_order == $menu_order){<br /> echo wp_get_attachment_image( $attachment->ID, $size );<br /> }<br /> }<br /> }<br /> }</code>
をfunction.phpにおき
<code><?php get_image_by_menu_order(get_the_ID(), ギャラリーの画像順序番号,'thumbnail'); ?></code>
みたいな感じで実現できるとおもいます。