2012-06-15 85 views
2

所以,我想顯示標題和摘要符合圖像?我怎樣才能做到這一點?Wordpress get_posts與圖像

<div id="treia_box" style="height:350px; width:350px;"> 
    <?php 
    add_filter('excerpt_length', 'new_excerpt_length'); 
    global $post; 
    $args = array('numberposts' => 3, 'category' => 29); 
    $myposts = get_posts($args); 
    foreach($myposts as $post) : setup_postdata($post); ?> 
    <h2><a href="<?php the_permalink(); ?>"<?php the_title('<h7>', '<h7>'); ?></a></h2> 
    <?php $size = array(75,75); 
echo get_the_post_thumbnail($post_id, $size)?> 
    <h6><?php the_excerpt(); ?></h6> 
    <?php endforeach; ?>  
</div> 

回答

1

get_the_post_thumbnail($post_id, $size)是正確的,但是:

1 - 你需要指定$大小,例如:「大」,「縮略圖」,「my_custom_size」

get_the_post_thumbnail($id, 'thumbnail');  // Thumbnail 
get_the_post_thumbnail($id, 'medium');  // Medium resolution 
get_the_post_thumbnail($id, 'large');   // Large resolution 

get_the_post_thumbnail($id, array(100,100)); // Other resolutions 

2 - 這將工作僅當用戶(您)定義後的縮略圖(特色 - 創建後,當圖像)