Php 创建wordpress post循环,根据顺序添加动态自定义样式类

Php 创建wordpress post循环,根据顺序添加动态自定义样式类,php,wordpress,Php,Wordpress,我需要在我的post循环中包含一个额外的样式,因此我最终会有额外的样式选项,如下所示: <article class="first-column format-standard hentry category-uncategorized"> <article class="second-column format-standard hentry category-uncategorized"> <article class="third-column format-

我需要在我的post循环中包含一个额外的样式,因此我最终会有额外的样式选项,如下所示:

<article class="first-column format-standard hentry category-uncategorized">
<article class="second-column format-standard hentry category-uncategorized">
<article class="third-column format-standard hentry category-uncategorized">
<article class="first-column format-standard hentry category-uncategorized">
<article class="second-column format-standard hentry category-uncategorized">
<article class="third-column format-standard hentry category-uncategorized">

然后它重复这个顺序。这样我就可以把我的帖子放三个宽,并且设计得很好

我想添加的关键内容是第一列、第二列等等

有关于在wordpress中添加什么的帮助吗

这就是当前创建此循环的原因:

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
循环外部的

$classes = array(
    0=>'first-column',
    1=>'second-column',
    2=>'third-column'
);
$i = 0;
<article id="post-<?php the_ID(); ?>" <?php post_class($classes[$i++%3]); ?>>
在您的循环中:

$classes = array(
    0=>'first-column',
    1=>'second-column',
    2=>'third-column'
);
$i = 0;
<article id="post-<?php the_ID(); ?>" <?php post_class($classes[$i++%3]); ?>>

谢谢你帮了我大忙

我把它用于我目前开发的一个引导主题,我想要两种背景颜色。每根柱子一个亮一个暗。因此,更容易识别每个新职位。很好,我刚用过

$classes = array(
    0=>'light-bg',
    1=>'darl-bg'
);
$i = 0;
<div id="post-<?php the_ID(); ?>" <?php post_class($classes[$i++%2]); ?>>
// The rest of your post html goes here
</div>
$classes=array(
0=>'light-bg',
1=>'darl-bg'
);
$i=0;

谢谢你。不过,上面的代码只是为所有这些类添加了“第一列”。请确保
$classes
$i
在循环之外声明(在
if(have_posts())之前),而(have_posts()):the_post();
)谢谢-我遇到了一个问题,其中一些循环是从另一个模板调用的,因此,代码的第一部分在一个文件中,其余部分在另一个文件中,它不是这样工作的?不确定它是如何工作的,添加
global$classes;全球1美元在您使用的每个文件的开头。