我试图添加一个“本地常见问题”部分到一个网站上的所有个人位置页面与字面上数千个单独的位置页面。我是通过在自定义post类型中使用ACF字段来做到这一点的。我已经在一个中转站点上实现了这一点。为了给本地FAQ部分一个标题,而不只是一个问答列表,我添加了一个h3,如下所示
<h3 class="local_faq" style="text-align: center; font-size: 50px;"><?php the_title(); ?> Dumpster Rental FAQs</h3>但是,由于有数千个这样的页面,我希望随着时间的推移实现这一点,这样我仍然可以发布我对生产站点所做的其他更改,因此我不希望这个h3在我还没有添加任何常见问题的页面上可见。
以下是本地常见问题部分的完整代码:
<h3 class="local_faq" style="text-align: center; font-size: 50px;"><?php the_title(); ?> Dumpster Rental FAQs</h3>
<div class="local_faq">
<?php if (get_field('local_faq')) : ?>
<?php while (the_repeater_field('local_faq')) : ?>
<div class="local_faq" style="margin-left: 100px; margin-right: 100px;">
<h4>
<?php the_sub_field('question'); ?>
</h4>
<p>
<?php the_sub_field('answer'); ?>
</p>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>那么,如果还没有输入常见问题,我如何隐藏h3呢?
发布于 2022-04-30 21:30:09
将外部(两个) div.local_faq移到if语句中,该语句检查faq字段是否已设置,因为这是外部父容器。另外,将外部容器div更改为具有复数div.local_faqs类而不是与嵌套div.local_faq相同的类也是有意义的。
然后,只需将h3部件添加到外部div.local_faqs中,faqs和header将只显示是否设置了字段:
<?php if (get_field('local_faq')) : ?>
<div class=“local_faqs”>
<h3 class="local_faq" style="text-align: center; font-size: 50px;"><?php the_title(); ?> Dumpster Rental FAQs</h3>
<?php while (the_repeater_field('local_faq')) : ?>
<div class="local_faq" style="margin-left: 100px; margin-right: 100px;">
<h4><?php the_sub_field('question'); ?></h4>
<p><?php the_sub_field('answer'); ?></p>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>https://wordpress.stackexchange.com/questions/405333
复制相似问题