【发布时间】:2018-07-27 20:39:23
【问题描述】:
我一直在尝试将手风琴块集成到 ACF 循环中:
<?php elseif ( get_row_layout() == 'accordeon' ) : ?>
<?php if ( have_rows( 'cases' ) ) : ?>
<div class="accordeon-bloc clear">
<?php while ( have_rows( 'cases' ) ) : the_row(); ?>
<div class="tab">
<input id="tab" type="checkbox" name="tabs">
<label for="tab"><?php the_sub_field( 'titre_du_bloc' ); ?></label>
<div class="tab-title"><?php the_sub_field( 'label' ); ?></div>
<div class="tab-content">
<p><?php the_sub_field( 'descriptif' ); ?></p>
</div>
</div>
<?php endwhile; ?>
</div>
<?php else : ?>
<?php // no rows found ?>
<?php endif; ?>
这里是 CSS:
input {
position: absolute;
opacity: 0;
z-index: -1;
}
.tab-content {
max-height: 0;
overflow: hidden;
transition: max-height .35s;
}
/* :checked */
.tab input:checked ~ .tab-content {max-height: 10em;}
所以这是我的问题:当我添加多个手风琴块时,我有几个选项卡 div,但是当我单击“+”以显示选项卡内容块时,它总是显示第一个的内容,如他们显然都有相同的类。
在构建循环之前我没有想到这个问题,我不知道如何解决这个问题。我对 javascript 的了解为零,但也许这里有解决方案?或者使用 CSS 并选择第 n 个/第 n + 1 个元素?
提前感谢您的帮助!
编辑: 我通过在 ADF 中添加 ID 字段并修改循环找到了解决方案:
<div class="tab">
<input id="<?php the_sub_field( 'identifiant' ); ?>" type="checkbox" name="tabs">
<label for="<?php the_sub_field( 'identifiant' ); ?>"><?php the_sub_field( 'icone' ); ?><?php the_sub_field( 'titre_du_bloc' ); ?></label>
<div class="tab-title"><?php the_sub_field( 'label' ); ?></div>
<div class="tab-content">
<p><?php the_sub_field( 'descriptif' ); ?></p>
</div>
</div>
但也许有更好的解决方案,不需要手动输入!
【问题讨论】:
-
能不能加个你现在用的js来显示内容?
-
没有 JS,因为手风琴是纯 CSS
-
你应该可以在不使用特定id输入的情况下实现它,检查答案
标签: wordpress loops repeater advanced-custom-fields