How can I make this PHP lines shorter?

前端 未结 4 1452
攒了一身酷
攒了一身酷 2021-01-25 12:45

I have this loop at the same it will count the output:

while ($wp_query->have_posts()) : $wp_query->the_post(); $current++; $current2++;

4条回答
  •  无人共我
    2021-01-25 13:06

    If you are just using these class names for alternating CSS styles there is a much elegant way to do this using CSS3

    Your HTML

    And in your css file

    .span4:nth-child(even) {background: #CCC}
    .span4:nth-child(odd) {background: #FFF}
    

    else for a PHP solution the answer by Liam Wiltshire should work good.

    source: CSS even and odd rules examples

提交回复
热议问题