我想在我的循環的每個第三個帖子中添加特殊類「last」以使我的列正確(我有3個垂直列)。Wordpress循環中的PHP計數器
我發現這段代碼在另一篇文章:
<?php $loop = new WP_Query(array('post_type' => 'portfolio')); ?>
<?php
$i = 1; //first value of $i
while ($loop->have_posts()) : $loop->the_post();
if($i % 3 == 0): // for every three post
$class = 'last';
else:
$class = '';
endif;
?>
<div class="four columns <?php echo $class ?>">
<?php the_content(); //along with other stuff in looped div ?
$i++;
>
</div>
<?php endwhile ?>
這似乎是正確的選擇,爲我,但我的問題是,我的文章顯示是這樣的:
<article id="post-<?php the_ID(); ?>" <?php post_class('et_pb_post'); ?>>
這意味着我不能將echo $class
添加到我的發短文中,並且我無法找到正確的語法來讓它正確。
有人嗎?謝謝 !使用上述的情況下
釷anks after 20聲望你可以在http://chat.stackoverflow.com/rooms/65335/wordpress-and-magento-developers – 2014-12-04 11:55:47