我知道你是ESL,但我想我们需要更多的细节。您需要更好地注释您的代码,这非常令人困惑。
不过我会猜一猜。
看一看Modulo %
操作人员
# Helper to simulate the while, replace this with `$wp_query->get_posts()` or similar
$posts = function() {
static $posts = 20;
$posts--;
return $posts < 0 ?: $posts;
};
$counter = 0;
echo "Looping Posts".PHP_EOL;
while( $posts() ) {
$counter++;
echo "Post: {$counter}".PHP_EOL;
if( $counter % 4 == 1 ) {
/* template A? */
echo \' (A)~~> Posts: 1, 5, 9, 13, 17, etc…\'.PHP_EOL;
} elseif( $counter % 4 == 2 ) {
/* template B? */
echo \' (B)~~> Posts: 2, 6, 10, 14, 18, etc…\'.PHP_EOL;
} elseif( $counter % 4 == 3 ) {
/* template C? */
echo \' (C)~~> Posts: 3, 7, 11, 15, 19, etc…\'.PHP_EOL;
} elseif( $counter % 4 == 0 ) {
/* template D? */
echo \' (D)~~> Posts: 4, 8, 12, 16, 20, etc…\'.PHP_EOL;
}
}
此处示例
3v4l.org, 您可以交互尝试。
输出:
Looping Posts
Post: 1
(A)~~> Posts: 1, 5, 9, 13, 17, etc…
Post: 2
(B)~~> Posts: 2, 6, 10, 14, 18, etc…
Post: 3
(C)~~> Posts: 3, 7, 11, 15, 19, etc…
Post: 4
(D)~~> Posts: 4, 8, 12, 16, 20, etc…
Post: 5
(A)~~> Posts: 1,