3

那么,我想根据图像显示标题和摘录?我怎样才能做到这一点?

<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>
4

1 回答 1

4

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

1 - 您需要指定 $size ,例如:“large”、“thumbnail”、“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 - 仅当用户(您)定义帖子缩略图时才有效(特色 - 创建帖子时的图像)

于 2012-06-15T12:43:35.420 回答