我更新了代码。我用回音交换回音。唯一的问题是post\\u thumbnail\\u url没有进入div的后台。
<?php
$args = array(
\'posts_per_page\' => 1,
\'category_name\' => \'news\',
);
$news_query = new WP_Query( $args );
if ( $news_query->have_posts() ) :
?>
<?php
$featured_img = get_the_post_thumbnail_url( $post->ID, \'full\' );
?>
<?php echo \'<div class="recent-news-banner" style="background: url(\' . $featured_img . \') no-repeat center center; background-size: cover;">\'; ?>
<?php
while ( $news_query->have_posts() ) : $news_query->the_post();
?>
<?php
$date = Date(\'F j, Y\');
$title = get_the_title($post->ID);
$link = get_the_permalink($post->ID);
?>
<?php echo \'<div class="\' . \'\' . \'"><div class="meta-date">\' . Date(\'F j, Y\') . \'</div><div class="meta-info"><div class="meta-title"><h5><a href="\' . get_permalink() . \'">\' . get_the_title() . \'</a></h5></div></div>\'; ?>
<?php
endwhile;
?>
<?php echo \'</div>\'; ?>
<?php else : ?>
<p><?php _e( "No News Found", \'news\' ); ?></p>
<?php wp_reset_postdata(); ?>
<?php endif
?>