【发布时间】:2017-09-06 12:17:34
【问题描述】:
我正在使用 if has_post_thumb 函数访问 WordPress 中自定义帖子类型的特征图像。一切都很好,除了 img 标签中的尾随 >" 实际上显示在页面上。我只是写错了吗?我必须将 php 保留在 src 属性中,因为 img 标签中有一些重要的 Bootstrap 类。请参阅代码如下:
<!-- create new loop and access custom post type for services using wordpress fxn -->
<!-- create var called loop and store a WP array for custom post type (CPT) services offered, ordered by id and ascending -->
<?php $loop = new WP_Query( array( 'post_type' => 'accolades', 'orderby' => 'post_id', 'order' => 'ASC') ); ?>
<!-- check to see if loop has posts and access posts from CPT. Same for all CPT -->
<?php while( $loop->have_posts() ) : $loop->the_post(); ?>
<!-- no acf used below it is all native WP using CPT -->
<div class="col-sm-4">
<div class="row">
<div class="col-sm-3">
<!-- check if there is a post thumbnail img or feature image. this grabs the feature img if there is one below. add an else statement to the if to display image if none uploaded -->
<img class="img-responsive img-circle" src="<?php if( has_post_thumbnail() ){ the_post_thumbnail(); } ?>">
</div><!-- /.col-sm-3 -->
<div class="col-sm-9">
<blockquote>
<!-- CPT content in content editor -->
<p><?php the_content(); ?></p>
<!-- CPT title -->
<small><?php the_title(); ?></small>
</blockquote>
</div><!-- /.col-sm-9 -->
</div><!-- /.row -->
</div><!-- /.col-sm-4 -->
<!-- close the while loop -->
<?php endwhile; ?>
【问题讨论】:
-
<?php echo ((has_post_thumbnalil()) ? the_post_thumbnail() : '' )?> -
the_post_thumbnail 显示图像 - 我认为您需要使用
标签: php html wordpress twitter-bootstrap