首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在手风琴中为我的循环发布wordpress函数

如何在手风琴中为我的循环发布wordpress函数
EN

Stack Overflow用户
提问于 2015-08-03 20:58:07
回答 1查看 585关注 0票数 0

因此,我试图创建一个垂直手风琴和每个部分的手风琴,我希望有一个博客文章。因此,基本上,我将有一个手风琴与最新的5个帖子。在每一篇文章中,我都将包括文章的日期、月份和年份以及帖子的标题。我假设我将使用PHP对spans或其他标记进行处理,但是当我将下面的标准循环添加到手风琴中时,我尝试过的每一种方法都会产生不同的结果,但不是我想要的结果。我在想id=“ac-1/2/3/4.”我得用PHP想出一个上升的数字或者别的什么?

代码语言:javascript
复制
    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;
代码语言:javascript
复制
<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中。

非常感谢你的时间/帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-03 21:07:08

您可以使用一个简单的计数器变量来做您想做的事情:

代码语言:javascript
复制
<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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31796641

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档