2016-10-15 48 views
0

我正在嘗試使用Wordpress'ACF plugin的圖庫字段加載項。該附加組件是Navz Photo Gallery。它所要做的就是給你一種獲取圖庫照片ID的方法。現在我想實際顯示圖像。顯示圖像知道他們的ID

通過調用下面的代碼

<?php if (get_field('field_name')) { ?> 
    <img src="<?php the_field('field_name'); ?>" /> 
<?php } ?> 

我得到的是實際的ID,像這樣:

<img src="21,22,23"> 

有誰知道如何循環通過這個組圖像並分別顯示出來,不只是身份證,而是實際的圖像?

僅供參考,ACF有一個官方的(付費)畫廊插件,並顯示附加的圖片是這樣的:

<?php $images = get_field('gallery'); if($images): ?> 
<?php foreach($images as $image): ?> 
    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /> 
<?php endforeach; ?> 
<?php endif; ?> 

回答

0

Navz幫助我這個:

<?php 
$images = get_field('fotos_do_projeto'); if($images): $images = explode(',', $images); $images = array_filter($images); if(count($images)): 
?> 
    <ul> 
    <?php foreach($images as $image): $alt = get_the_title($image); $url = get_post_meta($image, 'field_5802bd6e39e9b_url', true); ?> 
     <li> 
      <a href="<?php echo $url; ?>" title="<?php echo $alt; ?>"> 
       <?php echo wp_get_attachment_image($image, "thumbnail", false, ['alt' => $alt]); ?> 
      </a> 
     </li> 
    <?php endforeach; endif; ?> 
    </ul> 
<?php endif; ?> 
0

你可以試試這個,

$attachment_id = get_field('field_name'); 
    $image_attributes = wp_get_attachment_image_src($attachment_id); 
    if ($image_attributes) : ?> 
     <img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>" /> 
    <?php endif; ?> 
+0

謝謝你抽出時間 –

相關問題