2014-04-04 24 views
0

希望有人可以幫助。我已經把這段代碼放到了一個標準模板中,但是沒有顯示圖片,儘管事實上我已經有了一堆帶有圖片的帖子。WordPress的:顯示張貼在首頁的圖像

<?php if (have_posts()) : while (have_posts()) : the_post();  

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

if (empty($images)) { 
    // no attachments here 
} else { 
    foreach ($images as $attachment_id => $attachment) { 
     echo wp_get_attachment_image($attachment_id, 'thumbnail'); 
    } 
} 

endwhile; endif; ?> 

感謝您的幫助!

+0

你只需要顯示的圖像,沒有別的。並且圖片是否設置爲特色圖片 –

+0

不可以,它們不會被設置爲特色圖片。我只需要顯示圖像;我將使用砌體和CSS來定位它們。 – natnai

回答

1

變化

echo wp_get_attachment_image($attachment_id, 'thumbnail'); 

echo wp_get_attachment_image($attachment->ID, 'thumbnail'); 

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

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

你應該使用get_posts()

+0

仍然不工作:/ – natnai

+0

http://www.vcluxe.nu/ – natnai

+0

你會'print_r($ images)' – Dinesh

0

你可以做這樣的事情:

<?php if (have_posts()) : while (have_posts()) : the_post();  

$args = array(
    'post_type' => 'attachment', 
    'numberposts' => -1, 
); 

    $attachments = get_posts($args); 
    if ($attachments) { 
     foreach ($attachments as $attachment) { 
      echo wp_get_attachment_image($attachment->ID, 'full'); 
      } 
    } 

endwhile; endif; ?> 

此代碼將獲取從媒體庫中的所有「大」的圖像,並顯示它們

希望這是你正在尋找