1
我需要這個for循環在WordPress中,但我認爲也是純PHP的。 我需要我的交替DIV,我somethink這樣的:PHP替代'受保護的'第一個元素
// Here I getting total count of posts - return as INT, ex. 4
$countOffers = wp_count_posts('offer')->publish;
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<?php if ($countOffers % 2 == 0): ?>
// Align to left side
<?php get_template_part('template-parts/Offer/content', 'left'); ?>
<?php else: ?>
// Align to right side
<?php get_template_part('template-parts/Offer/content', 'right'); ?>
<?php endif ?>
<?php $countOffers--; ?>
<?php endwhile; ?>
它的正常工作,但我想「安全」的第一個元素左側。
這意味着無論我返回多少物品,它總是在左邊第一個。
你能只是增加一個'浮動:left'」這些元素? – WillardSolutions