2013-06-23 4 views
-1

내 클라이언트를위한 포트폴리오를 만드는 중입니다. 그래서 나는 작품의 이미지와 함께 작품을 추가 할 수있는 커스텀 포스트를 가지고있다.게시물의 WordPress 이미지 표시

그러나 슬라이드 쇼로 표시하려면 추천 이미지를 가져오고 슬라이드 쇼에 표시하려면 추천 이미지를 가져올 수 있지만 특정 아트웍 이미지를 슬라이드 쇼에 표시하면 다른 사용자가 넘길 수 있습니다.

이 내 현재 코드입니다 :

<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가 동적이 될 필요가 없습니까?

도움을 주시면 감사하겠습니다. 당신은 루프에있을 때

답변

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를 제공 get_children 기능에 'post_parent' => $post->ID,을 알 수 있습니다.

Check on Codex.

관련 문제