記事に埋め込んだギャラリーの中から1枚を抜き出してアーカイブに表示
-
早い話が、TwentyTenテーマで、’gallery’スラッグに入れられた投稿の中にギャラリーが埋め込まれていると、アーカイブ(loop.php)で、「この記事には**枚の画像があります」という表示とともに、ギャラリーの中から1枚だけ画像を抜粋表示するというデフォルト機能がありますよね。
あれを、TwentyTenじゃなく、自作テーマでやりたいのですが、どのようなコードを書いたらよいのかわかりません。
ぐぐったりして情報を探すと、アイキャッチ画像から引っ張ってくる方法や、投稿の本文内に使われている画像を引っ張ってくることは出来ましたが、ギャラリーから引っ張って来る方法がわからないのです。
TwentyTenの子テーマを作れば解決するのかもしれませんが、あくまでどういうコードを書けばいいのか教えていただけたら、大変ありがたいです。
2010のloop.phpのこの↓あたりにヒントがあると思うのですが。
functions.phpのどの部分を参考にすればいいのか、という検討が上手く付けられなくて行き詰っている状態です。<?php /* How to display posts in the Gallery category. */ ?> <?php if ( in_category( _x('gallery', 'gallery category slug', 'twentyten') ) ) : ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2> <div class="entry-meta"> <?php twentyten_posted_on(); ?> </div><!-- .entry-meta --> <div class="entry-content"> <?php if ( post_password_required() ) : ?> <?php the_content(); ?> <?php else : ?> <?php $images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) ); if ( $images ) : $total_images = count( $images ); $image = array_shift( $images ); $image_img_tag = wp_get_attachment_image( $image->ID, 'thumbnail' ); ?> <div class="gallery-thumb"> <a class="size-thumbnail" href="<?php the_permalink(); ?>"><?php echo $image_img_tag; ?></a> </div><!-- .gallery-thumb --> <p><em><?php printf( __( 'This gallery contains <a %1$s>%2$s photos</a>.', 'twentyten' ), 'href="' . get_permalink() . '" title="' . sprintf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ) . '" rel="bookmark"', $total_images ); ?></em></p> <?php endif; ?> <?php the_excerpt(); ?> <?php endif; ?>
2件の返信を表示中 - 1 - 2件目 (全2件中)
2件の返信を表示中 - 1 - 2件目 (全2件中)
- トピック「記事に埋め込んだギャラリーの中から1枚を抜き出してアーカイブに表示」には新たに返信することはできません。