dongwalun2507 2017-04-11 08:17
浏览 72
已采纳

使用img src属性中的if语句的WordPress特征图像

I am accessing the feature image of a custom post type in WordPress by using an if has_post_thumb function. Everything works great except the trailing >" in the img tag is actually displaying on the page. Am I just writing it wrong? I have to keep the php inside the src attribute because there is some important Bootstrap classes inside the img tag. Please see code below:

                    <!-- 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; ?>
  • 写回答

3条回答 默认 最新

查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境