最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Displaying specific posts from query thumbnail outside div

programmeradmin0浏览0评论

I'm trying to display thumbnails inside a div from a query, but the thumbnail is outside the div and I don't know what I'm doing wrong, here is my code:

<?php
// WP_Query arguments
$args = array(
    'post__in' => array(26844,26829),
    'post_type'              => array( 'wedstrijd' ),
    'post_status'            => array( 'published' ),
);

// The Query
$shquery = new WP_Query( $args );

// The Loop
if ( $shquery->have_posts() ) {
    while ( $shquery->have_posts() ) {
        $shquery->the_post();
        echo '<div class="wed_thumb">' . the_post_thumbnail('et-pb-post-main-image') . '</div>';
    }
} else {
    // no posts found
}

// Restore original Post Data
wp_reset_postdata();
?>

I'm trying to display thumbnails inside a div from a query, but the thumbnail is outside the div and I don't know what I'm doing wrong, here is my code:

<?php
// WP_Query arguments
$args = array(
    'post__in' => array(26844,26829),
    'post_type'              => array( 'wedstrijd' ),
    'post_status'            => array( 'published' ),
);

// The Query
$shquery = new WP_Query( $args );

// The Loop
if ( $shquery->have_posts() ) {
    while ( $shquery->have_posts() ) {
        $shquery->the_post();
        echo '<div class="wed_thumb">' . the_post_thumbnail('et-pb-post-main-image') . '</div>';
    }
} else {
    // no posts found
}

// Restore original Post Data
wp_reset_postdata();
?>
Share Improve this question edited Oct 16, 2019 at 11:47 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Oct 16, 2019 at 10:54 BielsBiels 1134 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

the_post_thumbnail will echo it, You should Use get_the_post_thumbnail instead to return image.

发布评论

评论列表(0)

  1. 暂无评论