2016-09-04 3 views
0

스폰서 이미지로 채워진 부트 스트랩 회전식 슬라이드 쇼를 보여주는 테마를 개발했습니다.Wordpress의 미디어 라이브러리에서 특정 이미지 가져 오기

<div class="item active"> 
    <div class="row outerDiv"> 
    <div class="col-xs-12 innerDiv"> 
     <a href="<?php echo bloginfo('url'); ?>/recruiting-messe/"><img class="carImg img-responsive" src="<?php bloginfo('template_url')?>/images/Sponsoren/PremiumSponsoren.jpg" alt="Premium Sponsoren" style="margin: 0 auto;"></a> 
    </div> 
    </div> 
</div> 

내가 내 저자는 코드 자체에 파고 필요없이 이미지를 변경할 수 있도록하려면,하지만 난 갈 방법을 모른다 : 는 순간에 스폰서-이미지는 다음과 같이 하드 코딩되어있다 그것에 대해. 특정 명명 규칙이나 루프가있는 캡션 "스폰서"를 사용하여 미디어 라이브러리에 업로드 된 이미지를 검색하는 방법에 대해 생각해 보았습니다. 이와 같은 것을 구현하는 가장 좋은 방법은 무엇입니까? 미리 감사드립니다.

답변

1

이와 비슷한 것.

$attachment_meta = wp_get_attachment(your_attachment_id); 
$caption = $attachment_meta['caption']; 

if($caption == 'sponsor') : 
// show me the money 
endif; 
1

플러그인을 사용하면 어떨까요? 또는 게시물을 지정하고, 갤러리를 첨부하고, 간단한 부트 스트랩 회전 목마를 사용하기 위해 갤러리 단축 코드를 사용할 수 있습니까? 희망이 도움이됩니다.

1

아마도 다음을 수행 할 수 있습니다. this과 같은 일부 메타 필드 플러그인을 사용하고 작성자가 어떤 이미지가 스폰서를 선택할 수 있는지 이미지 필드를 추가하십시오. 그러면 다음과 같이 할 수 있습니다.

if($current_attachment_id == get_field('image_field')){ 
    //Do the trick 
} 
0

도움을 주신 모든 분들께 감사드립니다. 특정 제목 "SponsorenBanner"첨부 파일을 쿼리하여 문제를 해결했습니다.

$query_images_args = array(
     'post_type'  => 'attachment', 
     'post_mime_type' => 'image', 
     'post_status' => 'inherit', 
     'posts_per_page' => - 1, 
     'title' => 'SponsorenBanner', 
     'order' => 'ASC', 
    ); 

    $query_images = new WP_Query($query_images_args); 

    $images = array(); 
    foreach ($query_images->posts as $image) { 

     $images[] = wp_get_attachment_url($image->ID); 

    } 
관련 문제