首页 > 解决方案 > 在 wordpress 中,在新页面上上传图片,但这些图片显示在前端

问题描述

在此处输入图像描述

在此处输入图像描述

我在页面上上传图片,但这些图片没有显示在前端。这是我 page.php 的代码

<?php get_header(); ?>   
<section class="container">
<div class="row">
<div class="col-md-12 col-sm-12 col-hs-4 col-xs-12">
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
            <article <?php post_class() ?> id="post-<?php the_ID(); ?>">
                <header>
                  <h1><?php the_title(); ?></h1>
            </header>
            <section>
                <?php the_content(); ?>
          <hr class="clearfix" />
                  <?php edit_post_link('Edit', '<p>', '</p>'); ?>
              </section>
                <hr class="clearfix" />
            </article>
    <?php endwhile; else: ?>
        <p>Sorry, no posts matched your criteria.</p>
    <?php endif; ?>
</section>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 col-sm-5 hidden-xs hidden-hs">
<?php get_sidebar(); ?>
<?php get_footer(); ?>

标签: phpwordpress

解决方案


那是因为the_content()只输出内容而不输出图像。您将需要输出图像做一些事情,

  $image_attr = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium');

  // Now you are working with $image_attributes array and display whatever you want

在这里阅读更多https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/


推荐阅读