将特色图片显示为缩略图?
Display featured image as thumbnail?
我目前正尝试在我的主页上显示来自类别的 post 以及图像(特色图像)。
到目前为止,我有这段代码可以获取 post 并将其显示在我的主页上:
<div class="row">
<div class="col-md-6">
<?php query_posts('cat=4');
while (have_posts()) : the_post();
the_content();
endwhile;?>
</div>
这确实显示了,但我现在也尝试设置特色图片。
我希望它显示为:
我看到了一些建议,例如
<?php the_post_thumbnail(); ?>
但我不是 100% 知道在哪里添加这个。
提前超级感谢!
你应该这样做:
<div class="row">
<div class="col-md-6">
<?php query_posts('cat=4');
while (have_posts()) : the_post();
if ( has_post_thumbnail() ) {
the_post_thumbnail('thumbnail');
}
the_content();
endwhile;?>
</div>
您可能需要将 the_content 和 the_post_thumbnail 包装在 div 中并使用 CSS 设置样式,或者使用主题
中的列 类
你可以试试这个,不过还没有测试过。我将 args
保留为数组,以防您要添加其他内容。
<div class="row">
<div class="col-md-6">
<?php
$args = array( 'cat' => 4 );
$loop = new WP_Query( $args );
while ($loop->have_posts() ) : $loop->the_post();
?>
<div style="float: left;">
<?php the_post_thumbnail( 'thumbnail' ); ?>
</div>
<?php the_content(); ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>
</div>
我目前正尝试在我的主页上显示来自类别的 post 以及图像(特色图像)。
到目前为止,我有这段代码可以获取 post 并将其显示在我的主页上:
<div class="row">
<div class="col-md-6">
<?php query_posts('cat=4');
while (have_posts()) : the_post();
the_content();
endwhile;?>
</div>
这确实显示了,但我现在也尝试设置特色图片。
我希望它显示为:
我看到了一些建议,例如
<?php the_post_thumbnail(); ?>
但我不是 100% 知道在哪里添加这个。
提前超级感谢!
你应该这样做:
<div class="row">
<div class="col-md-6">
<?php query_posts('cat=4');
while (have_posts()) : the_post();
if ( has_post_thumbnail() ) {
the_post_thumbnail('thumbnail');
}
the_content();
endwhile;?>
</div>
您可能需要将 the_content 和 the_post_thumbnail 包装在 div 中并使用 CSS 设置样式,或者使用主题
中的列 类你可以试试这个,不过还没有测试过。我将 args
保留为数组,以防您要添加其他内容。
<div class="row">
<div class="col-md-6">
<?php
$args = array( 'cat' => 4 );
$loop = new WP_Query( $args );
while ($loop->have_posts() ) : $loop->the_post();
?>
<div style="float: left;">
<?php the_post_thumbnail( 'thumbnail' ); ?>
</div>
<?php the_content(); ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>
</div>