我正在自定义WordPress模板,我将在主页中的摘录帖子可视化中实现以下行为:
If a post contains images (one or more), in the homepage post preview show at the begining a thumbnail of the first image that is in the post, then show the excerpt of the post.
目前,我有以下代码,在WordPress循环中显示主页中所有帖子的摘录:<!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
<?php the_excerpt(); ?>
<?php wp_link_pages( array( \'before\' => \'<div class="page-link"><span>\' . __( \'Pages:\', \'admired\' ) . \'</span>\', \'after\' => \'</div>\' ) ); ?>
</div>
正如您所看到的,这个代码片段显示了一篇文章的摘录。在摘录可视化之前,是否可以在帖子中找到第一个图像,将其放入变量并在span(或其他一些HTML标记)中显示?