我有一个站点的 2 个版本,一个实时测试版本和一个本地版本。
我目前正在使用 MAMP 开发本地版本。两个站点的后端是相同的,我确保每个站点的管理员完全相同。
我正在尝试通过编辑页面 部分向站点添加图像,但图像没有显示。
我检查了该站点以查看任何错误,没有发现任何错误,但是我遇到了一些有趣的事情。
并排比较两个站点版本的 html 标记后,我注意到我的本地版本缺少显示图像的 div。
这里是 live 版本的 div -
正如您在本地版本中看到的那样,有一个 ul
而不是 div class="image-16-8
。
这是显示这些图像的 php 文件
<?php
function tbhHeroShortcode($atts)
{
$values = shortcode_atts(array(
'images' => '',
'first-line' => '',
'second-line' => '',
'video' => '',
'link' => '',
), $atts);
ob_start();
?>
<div class="hero">
<?
$images = decode_shortcode_data($values['images']);
if ($images): ?>
<ul data-simple-slider>
<?php foreach ($images as $image): ?>
<li>
<div class="image-16-8" style="background-image: url(<?= $image->url; ?>); "></div>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<div class="hero-content">
<div class="hero-content-first-line">
<h1 class="header"><?= decode_shortcode_data($values['first-line']) ?></h1>
</div>
<h1 class="italic-header"><?= decode_shortcode_data($values['second-line']) ?></h1>
<div class="hero-content-cta">
<a class="hollow-button" href="<?= decode_shortcode_data($values['link']) ?>">Learn More</a>
</div>
</div>
<?php if (count($images) > 1): ?>
<div class="hero-controls">
<i class="fa fa-chevron-left hero-controls__left" aria-hidden="true"></i>
<i class="fa fa-chevron-right hero-controls__right" aria-hidden="true"></i>
</div>
<?php endif; ?>
</div>
<?php
$component = ob_get_contents();
ob_end_clean();
return $component;
}
add_shortcode('tbhHero', 'tbhHeroShortcode');
有人知道为什么会这样吗?
最佳答案
显示 ul 是因为它就在您的 php 中
<div class="hero">
<?
$images = decode_shortcode_data($values['images']);
if ($images): ?>
<ul data-simple-slider>
但是,在您的实时版本截图中,您的英雄 div 不同,它看起来像这样
<div class="hero" id>
您看到的输出不是由同一个文件生成的,因此要么存在一些浏览器/服务器缓存正在进行并且您从实时站点看到的内容不反射(reflect)您的 php 的当前状态,要么您的 php 以某种方式两个环境之间的文件更新不同步。
关于php - Wordpress div 未显示在站点的本地主机版本上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47060135/