如何在div下打印<li> 10次?

时间:2017-05-10 06:57:25

标签: php html wordpress html5

我正在使用WordPress创建一个网站,我有一个名为<div class="column dt-sc-one-half">的div,根据该版块,我有一个名为<ul class="menu-card check">的ul,并在此<ul>下打印<li> 1}}通过while循环10次。但我总共有50 <li>,我想在此<li>下打印10 <div>,在下一个div下打印下一个10,依此类推。

为此,我写了一段代码,但不知道为什么它没有发生

<?php query_posts('page_id=5'); ?>
<?php while(have_posts()) : the_post();?>
<?php
if( have_rows('price_chart') ): while ( have_rows('price_chart') ) : 
the_row();
if( get_row_layout() == 'price_chart' ):?>

<?php
$i=0; ?>
<div class="column dt-sc-one-half">
<ul class="menu-card check">
<?php
while($i<10)
{
?>

<li><?php echo get_sub_field('item'); ?><span><?php echo 
get_sub_field('price'); ?></span></li>


<?php
++$i;
}
?>

</ul>
</div>



<?php endif;endwhile;endif;endwhile; ?>

这意味着我想要一个像这样的结构

                                <div class="column dt-sc-one-half">
                                <ul class="menu-card check">
                                    <li>Women's haircut<span>$75</span></li>
                                    <li>Shampoo And Style<span>$55</span></li>
                                    <li>Blow Dry Style<span>$49</span></li>
                                    <li>Thermal Press Style<span>$51</span></li>
                                    <li>Dandruff Rinse<span>$25</span></li>
                                    <li>Hair Coloring<span>$30</span></li>
                                    <li>Hair Color Removal<span>$35</span></li>
                                    <li>Hair And Scalp<span>$19</span></li>
                                    <li>Lash And Brow Tint<span>$38</span></li>
                                    <li>Cap Frosting<span>$25</span></li>
                                </ul>
                            </div>
                            <div class="column dt-sc-one-half">
                                <ul class="menu-card check">
                                    <li>Women's haircut<span>$75</span></li>
                                    <li>Shampoo And Style<span>$55</span></li>
                                    <li>Blow Dry Style<span>$49</span></li>
                                    <li>Thermal Press Style<span>$51</span></li>
                                    <li>Dandruff Rinse<span>$25</span></li>
                                    <li>Hair Coloring<span>$30</span></li>
                                    <li>Hair Color Removal<span>$35</span></li>
                                    <li>Hair And Scalp<span>$19</span></li>
                                    <li>Lash And Brow Tint<span>$38</span></li>
                                    <li>Cap Frosting<span>$25</span></li>
                                </ul>
                            </div>

但我正在获得这种结构

<div class="column dt-sc-one-half">
                                <ul class="menu-card check">
                                    <li>Women's haircut<span>$75</span></li>
                                    <li>Women's haircut<span>$75</span></li>
                                    <li>Women's haircut<span>$75</span></li>
                                    <li>Women's haircut<span>$75</span></li>
                                    <li>Women's haircut<span>$75</span></li>
                                    <li>Women's haircut<span>$75</span></li>
                                    <li>Women's haircut<span>$75</span></li>
                                    <li>Women's haircut<span>$75</span></li>
                                    <li>Women's haircut<span>$75</span></li>
                                    <li>Women's haircut<span>$75</span></li>
                                </ul>
                            </div>
                            <div class="column dt-sc-one-half">
                                <ul class="menu-card check">
                                    <li>Shampoo And Style<span>$55</span></li>
                                    <li>Shampoo And Style<span>$55</span></li>
                                    <li>Shampoo And Style<span>$55</span></li>
                                    <li>Shampoo And Style<span>$55</span></li>
                                    <li>Shampoo And Style<span>$55</span></li>
                                    <li>Shampoo And Style<span>$55</span></li>
                                    <li>Shampoo And Style<span>$55</span></li>
                                    <li>Shampoo And Style<span>$55</span></li>
                                    <li>Shampoo And Style<span>$55</span></li>
                                    <li>Shampoo And Style<span>$55</span></li>
                                </ul>
                            </div>

2 个答案:

答案 0 :(得分:3)

您有额外endwhile删除此内容。无需添加此内容。

PHP有两种语法

<?php
/* example 1 */

$i = 1;
while ($i <= 10) {
    echo $i++;  /* the printed value would be
                   $i before the increment
                   (post-increment) */
}

/* example 2 */

$i = 1;
while ($i <= 10):
    echo $i;
    $i++;
endwhile;
?>

你们两个都混在一起。

答案 1 :(得分:2)

$ i在代码中没有正确递增

<?php
++$i;

}
?>