gpt4 book ai didi

php - wordpress 拆分
  • 以形成 3 列
  • 转载 作者:行者123 更新时间:2023-11-28 08:34:44 25 4
    gpt4 key购买 nike

    我目前使用它来将我存档的帖子放入年份和月份列表中,并列出帖子数量。我不确定如何破解 <li>与计数。我希望它用 4 <li> 将它们均匀地分成 3 列每列。我尝试使用 CSS3 列来解决问题,但它会导致 <li>有点靠不住。

    这是我的代码:

         <?php
    $year_prev = null;
    $months = $wpdb->get_results( "SELECT DISTINCT MONTH( post_date ) AS month,
    YEAR( post_date ) AS year,
    COUNT( id ) as post_count FROM $wpdb->posts
    WHERE post_status = 'publish' and post_date <= now( )
    and post_type = 'post'
    GROUP BY month , year
    ORDER BY post_date DESC");
    foreach($months as $month) :
    $year_current = $month->year;

    if ($year_current != $year_prev){
    if ($year_prev != null){?>
    </ul></div><div class="clear"></div>
    <?php } ?>
    <div class="archive-year-row"><h3><?php echo $month->year; ?></h3>
    <ul class="archive-list">
    <?php } ?>
    <li>
    <a href="<?php bloginfo('url') ?>/<?php echo $month->year; ?>/<?php echo date("m", mktime(0, 0, 0, $month->month, 1, $month->year)) ?>">
    <span class="archive-month"><?php echo date("F", mktime(0, 0, 0, $month->month, 1, $month->year)) ?></span>
    <span class="archive-count"><?php echo $month->post_count; ?></span>
    </a>
    </li>
    <?php $year_prev = $year_current;
    endforeach; ?>
    </ul>

    最佳答案

    所以基本上只要设置 $i = 1;在每个操作之后。然后迭代 $i++;就在关闭 foreach 之前。

    然后您可以使用 $i 作为计数器并测试 $i 的值。

    像这样。

    if($i == 4 || $i ==8){
    echo "</ul><ul>"; // this assumes you are opening and closing your column with the <ul></ul> tags
    }

    这不是完整的代码,但应该为您指明正确的方向。

    关于php - wordpress 拆分 <li> 以形成 3 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28101388/

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