gpt4 book ai didi

php - 如何在一个div下打印10次
  • 转载 作者:行者123 更新时间:2023-11-28 05:17:08 25 4
    gpt4 key购买 nike

    我正在用 wordpress 创建一个网站,我有一个名为 <div class="column dt-sc-one-half"> 的 div在它下面我有一个名为 <ul class="menu-card check"> 的 ul在这个 <ul> 下我正在打印 <li>通过 while 循环 10 次。但我总共有 50 <li>我只想打印 10 <li>在这个<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>

    最佳答案

    你有额外的 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;
    ?>

    你把两者混合了。

    关于php - 如何在一个div下打印10次<li>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43885483/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com