2011-06-17 75 views
0

由於某種原因,我無法獲得附件顯示,如果我通過$ attachment_id,如果我傳遞一個真實的值像187它的作品。Wordpress WP_Query

我正在使用WpAlchemy和Custom Image Sizes插件。

<section id="new"> 
<?php $myquery = new WP_Query(array('post_type' => array('post', 'website_gallery'),'showposts' => '2')); 
    while ($myquery->have_posts()) : $myquery->the_post(); 
    global $custom_metabox; 
?> 
    <div class="latest hentry"> 
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
    <?php $website_gallery->the_meta(); ?> 
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> 
     <img src="<?php $website_gallery->the_value('galleryimage');?>" alt="<?php the_title(); ?>"> 
    </a> 
    <?php echo wp_get_attachment_image($attachment_id, '220x80'); ?> 
    </div> 
    <?php endwhile; wp_reset_query(); ?> 
</section> 
+0

你在哪裏設置$ attachment_id? – 2011-06-17 02:33:19

回答

0

我想你可以通過使用get_post()函數來獲取連接ID。 get_post()需要數組爲它的參數和數組可以是這樣的:

$args = array('post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID); 

既然你想要的附件,請確保您的'post_type' => 'attachment'

你可以再做:

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

適應的代碼爲你所需要的。希望它能爲你工作。

退房:http://codex.wordpress.org/Template_Tags/get_posts#Show_attachments_for_the_current_post

+0

謝謝你以前的工作,但沒有成功。我認爲這是我用來調整圖像大小的插件。 – showFocus 2011-06-17 12:05:56