因此,我试图创建一个垂直手风琴和每个部分的手风琴,我希望有一个博客文章。因此,基本上,我将有一个手风琴与最新的5个帖子。在每一篇文章中,我都将包括文章的日期、月份和年份以及帖子的标题。我假设我将使用PHP对spans或其他标记进行处理,但是当我将下面的标准循环添加到手风琴中时,我尝试过的每一种方法都会产生不同的结果,但不是我想要的结果。我在想id=“ac-1/2/3/4.”我得用PHP想出一个上升的数字或者别的什么?
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><h2>
<?php the_content(); ?>
<?php endwhile;
else :
echo '<p>Nothing here!</p>';
endif;<section class="ac-container">
<div>
<input id="ac-1" name="accordion-1" type="checkbox" />
<label for="ac-1">Blog Post 1</label>
<article class="ac-small">
<p>Blog Post 1 Content</p>
</article>
</div>
<div>
<input id="ac-2" name="accordion-1" type="checkbox" checked />
<label for="ac-2">Blog Post 2</label>
<article class="ac-medium">
<p>Blog Post 2 Content</p>
</article>
</div>
<div>
<input id="ac-3" name="accordion-1" type="checkbox" />
<label for="ac-3">Blog Post 3</label>
<article class="ac-large">
<p>Blog Post 3 Content</p>
</article>
</div>
<div>
<input id="ac-4" name="accordion-1" type="checkbox" />
<label for="ac-4">Blog Post 4</label>
<article class="ac-large">
<p>Blog Post 4 Content</p>
</article>
</div>
</section>有人明白我的意思吗?我可以使用这些循环函数获得输出,但结果不正确,因为我认为每个输入都有不同的ID会引起混淆。当然,这在我的header.php中。
非常感谢你的时间/帮助。
发布于 2015-08-03 21:07:08
您可以使用一个简单的计数器变量来做您想做的事情:
<section class="ac-container">
<?php
$counter = 0;
if (have_posts()) :
while (have_posts()) : the_post(); $counter++; ?>
<div>
<input id="ac-<?php echo $counter;?>" name="accordion-1" type="checkbox" />
<label for="ac-<?php echo $counter;?>"><?php the_title();?></label>
<article class="ac-small">
<?php the_content();?>
</article>
</div>
<?php endwhile;
else :
echo '<p>Nothing here!</p>';
endif;?>
</section>https://stackoverflow.com/questions/31796641
复制相似问题