2011-03-28 57 views
1

我的問題很簡單:是否可以在帖子中同時導入多個圖像(例如圖庫),但是在<ul>之內? 我認爲,圖庫導入是在帖子內導入一組圖像的唯一方式,但在這種情況下我無法處理HTML。 我可能是錯的,但我沒有找到任何有關的。感謝您的幫助。如何將圖像導入爲Wordpress中的HTML列表?

回答

2

您可以將圖像插入到圖庫中,而不必將其導入到帖子中。然後,在單個帖子模板中,您可以查詢附加到該帖子的圖像以顯示它們。

附件只是在訊息的帖子,讓我們用get_posts():

function get_post_images($post) { 
    $args = array(
     'post_type' => 'attachment', // Images attached to the post 
     'numberposts' => -1, // Get all attachments 
     'post_status' => null, // I don’t care about status for gallery images 
     'post_parent' => $post->ID, // The parent post 
     'exclude' => get_post_thumbnail_id($post->ID), // Exclude the thumbnail if you want it on your article list but not inside an article 
     'post_mime_type' => 'image', // The attachment type 
     'order' => 'ASC', 
     'orderby' => 'menu_order ID', // Order by menu_order then by ID 
    ); 
    return get_posts($args); 
} 

我建議把這個函數在functions.php文件。

在你的single.php文件:

<ul> 
<?php 
    $images = get_post_images($post); 
    foreach ($images as $image): 
?> 
<li><?php echo wp_get_attachment_image($image->ID, 'medium'); ?></li> 
<?php endforeach; ?> 
</ul> 

WP食品鏈接:

+0

這是我在等待答案,但我仍然認爲這是缺乏WordPress的管理員。作者可以批量導入圖片而不使用這個奇怪的畫廊概念。謝謝你。你沒有? – rooofl 2011-03-28 11:11:30

+0

是的,WordPress的糟透了媒體管理。而且我是拉斯塔。神話握手! – bpierre 2011-03-28 13:30:07