wordpress如何将3列发布列表和列包装

时间:2017-10-30 09:47:42

标签: wordpress post

我正在尝试使用以下结构加载WordPress博客列表。

这是我的代码

enter image description here

(div class="left-wrap)
post-1
post-4
post-7

(div class="right-wrap)
post-2
post-3
post-5
post-6
(/div)

POST 1 | POST 2,POST 3

POST 4 | POST 5,POST 6

POST 7 | POST 8,POST 7

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

如下所示填充post数组,并分别循环显示左侧和右侧部分

<?php 
    $posts = ["one", "two", "three", "four", "five","six", "seven", "eight", "nine", "ten"];
    $left_array = [];
    $right_array = [];
    foreach($posts as $key => $post){
        if(($key+1) % 3 == 1){
          $left_array[] = $post;
        }
        else{
           $right_array[] = $post;
        }
    }

    print_r($left_array);
    print_r($right_array);

    ?>

<强>输出

LEFT ARRAY

Array
(
    [0] => one
    [1] => four
    [2] => seven
    [3] => ten
)

正确的阵营

Array
(
    [0] => two
    [1] => three
    [2] => five
    [3] => six
    [4] => eight
    [5] => nine
)