php - wordpress显示第二个三个帖子

标签 php wordpress posts

我需要显示:

first three posts in first div from wordpress,

second three posts in second div from wordpress and

third three posts in third div from wordpress.

我该怎么做?

div 1
    --1st post
    --2nd tpost
    --3rd post
div 2
    --4th post
    --5th post
    --6th post
div 3
    --7th post
    --8th post
    --9th post

最佳答案

您可以通过多种方法来完成。将数据放入数组中,然后 chunk()它,并循环遍历这些 block 。

或者,您可以简单地遍历数据:

<div class="...">
    <?php
    // Set counter
    $i = 1;

    // Loop over your posts
    while (have_posts()) {
        // If you have ouputted three already then close and reopen div
        if ($i == 3) {
            $i = 1;

            echo '</div><div class="...">';
        }

        // Output the post and increment the counter
        the_content();
        $i++;
    }
    ?>
</div>

关于php - wordpress显示第二个三个帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30636918/

相关文章:

JavaScript 文件随机损坏?

django - Wagtail - 仅在主页上显示三个最新帖子

javascript - blogspot.com 同一标签的所有帖子列表

facebook - 通过 Facebook App 发布公开帖子?

php - Nette Framework - 将所有内容路由给一位演示者

PHP,Doctrine,使用不同 "where"和 "on"的连接

php - python 后端有什么用途?

WordPress 中使用 pre 和 code 标签格式化 HTML 代码

magento - 将 Magento "Add to Cart"按钮移动到新文件不起作用

php - 具有多个 AND 的 MySQL 查询