【问题标题】:Div class name with $count; in wordpress loop带有 $count 的 div 类名;在 wordpress 循环中
【发布时间】:2015-02-10 19:13:31
【问题描述】:

我需要添加一个 $count;在类名之后到循环内的帖子 div。含义示例: - 所以帖子的类将是 mypost1、mypost2...

我可以正常工作,但我不知道如何在类名后添加 $count。

<?php $count = 0; if ( have_posts() ) : while ( have_posts() ) : the_post(); $count++; ?>
<div class="mypost">...</div>
<?php endwhile; endif; ?>

【问题讨论】:

    标签: css wordpress loops


    【解决方案1】:

    只需在适当的位置echo您的变量:

    <?php $count = 0; if ( have_posts() ) : while ( have_posts() ) : the_post(); $count++; ?>
    <div class="mypost<?php echo $count; ?>">...</div>
    <?php endwhile; endif; ?>
    

    【讨论】:

    • @MichalBěhal 别担心。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-27
    • 1970-01-01
    • 2011-09-02
    • 2014-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多