php - 在 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(); ?>
解决方案
那是因为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/
推荐阅读
- jquery - 根据第一个日期选择器设置第二个日期选择器的 minDate
- c# - [CascadingParameter] 与 [Parameter] 相比是否会影响性能?
- security - 如何删除服务器标头 .NET Core Blazor 应用程序
- javascript - 如何将 Buffer.from() 与 crypto.timingSafeEqual() 一起使用?
- .net - C# 中的双精度魔法
- ios - SceneKit 节点的交集
- python - 根据字典在 csv 中搜索单词
- .net - 尝试在 Azure 管道 PATH ISSUE 上部署 SQL DB
- sql-server - 在sql的列中找出不包含特定值的字段
- javascript - 我想从数据库中获取图像路径并将其显示在反应组件中,我正在使用 require(),(错误:找不到模块)发生?