我想在下面的图片中显示和隐藏文章。我的代码正在努力展示第一篇文章,但我希望能够处理所有文章。
事情是:我使用的是ACF灵活内容,所以我无法找到如何和#34;目标"文章。
如何将这种效果应用于通过acf灵活内容生成的所有文章?
的CSS:
.content {display: none;}
动画:
$(document).ready(function() {
$("#toggle").click(function() {
$(this).parents('h1').next('.contenu_atelier').fadeToggle(500);
});
});
PHP:
if( have_rows('ateliers') ):
while ( have_rows('ateliers') ) : the_row();
if( get_row_layout() == 'atelieratelier' ):
<div id="Workshop">
<!-- Buttons -->
<h1><button id="toggle" ><?php the_sub_field('atelier_01');?></button></h1>
<!-- Article to show -->
<div id="content">
<p class="some-texte"><?php the_sub_field('my-article-text');?></p>
</div>
</div>
endif;
endwhile;
else :
endif;
答案 0 :(得分:0)
最后我更改了php的结构,并添加了javascript效果
(不要忘记加载jquery)
javascript:
void Remove(char *code){
for (int i = 0; i < _curSize; i++){
if (strcmp(code, products[i]->getCode()) == 0){
delete products[i]; // A correct/important step
products[i] = NULL; // Totally useless, but not harmful
// products[i] = new Product(); // Useless and harmful, creates a memory leak
products[i] = products[_curSize-1]; // A correct/important step
// delete products[_curSize-1]; // Very harmful: program crashes.
products[_curSize-1] = NULL; // Maybe useful, anyway not harmful.
_curSize -= 1; // A correct/important step
return;
}
}
php:
$(document).ready(function($) {
var allPanels = $('.accordion > dd').hide();
$('.accordion > dt > a').click(function() {
allPanels.slideUp();
$(this).parent().next().slideDown();
return false;
});
$('.accordion > dt > a').eq(0).click()
})(jQuery);
css:
<div class="accordion">
<?php
if( have_rows('ateliers') ):
while ( have_rows('ateliers') ) : the_row();
if( get_row_layout() == 'atelieratelier' ):?>
<dt>
<a href=""><h3><?php the_sub_field('atelier_01');?></h3></a>
</dt>
<dd>
<?php the_sub_field('my-article-text');?>
</dd>
<?php endif;
endwhile;
else :
// no layouts found
endif;
?>