-1

私がやろうとしているのは、クライアントのポートフォリオを作成することです。だから私は彼女が作品の画像と一緒にアートワークを追加できるカスタム投稿を持っています.

ただし、スライドショーに表示したいのですが、スライドショーに注目の画像を表示することはできますが、その特定のアートワークのすべての画像をスライドショーに表示して、誰かがそれらをめくることができるようにします。

これは私の現在のコードです:

<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Carousel items -->
<div class="carousel-inner">
<div class="active item"><?php the_post_thumbnail( 'wpbs-featured' ); ?></div>
<div class="item"><?php echo wp_get_attachment_image( 1 ); ?></div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>
</div>

そのため、注目の画像を取得していますが、その特定の投稿のスライド ショーに表示される残りの画像が必要です。

wp_get_attachment_image を使用してみましたが、どうすれば ID が何であるかを知ることができますか? また、新しいアートワークはすべて異なる ID を持つ別の投稿になるため、ID は動的である必要はありませんか?

どんな助けでも大歓迎です。

4

1 に答える 1

0

ループにいるときは、使用できます

$images = get_children( array (
    'post_parent' => $post->ID,
    'post_status' => 'inherit',
    'post_type' => 'attachment',
    'post_mime_type' => 'image'
));

if ( count($images) ) {
    $size = 'thumbnail';  // medium, large
    $output = '';
    foreach ( $images as $id => $attachment ) {
        $title = esc_html( $attachment->post_title, 1 );
        $img = wp_get_attachment_image_src( $id, $size );
        $output .= '<a class="selector $size" href="' . esc_url( wp_get_attachment_url( $id ) ) . '" title="' . esc_attr( $title ) . '">';
        $output .= '<img class="aligncenter" src="' . esc_url( $img[0] ) . '" alt="' . esc_attr( $title ) . '" title="' . esc_attr( $title ) . '" />';
        $output .= '</a>';
    }
   // Now do something with $output
   // which is collection of images wrapped with <a> from one post;
   // something like
   // <a href="..." title="..."><img src="..." alt="..." title="..." /></a>
   // <a href="..." title="..."><img src="..." alt="..." title="..." /></a>
}

ループ内から、関数$post->IDで投稿 ID、通知を​​取得'post_parent' => $post->ID,get_childrenます。

Codex で確認してください

于 2013-06-23T18:57:44.097 に答える