admin管理员组文章数量:1296919
Will be pleased for any help! The site is done on bootstrap.
I have 3 column site.
I want simply to add class clearfix if number of posts % 3 == 0;
I can add only through browser DevTools
I have my posts code as fallowing:
$pages = get_posts( array(
'numberposts' => -1,
'category' => '20',
'orderby' => 'ID',
'order' => 'ASC',
'post_type' => 'post',
));
foreach( $pages as $post )
setup_postdata($post);
I'm doing this way but it doesn't work.
foreach( $pages as $post ) {
if ($post[0] % 3 == 0) {
setup_postdata($post.'<\div class="clearfix"\>');
}
else {
setup_postdata($post);
}
Will be pleased for any help! The site is done on bootstrap.
I have 3 column site.
I want simply to add class clearfix if number of posts % 3 == 0;
I can add only through browser DevTools
I have my posts code as fallowing:
$pages = get_posts( array(
'numberposts' => -1,
'category' => '20',
'orderby' => 'ID',
'order' => 'ASC',
'post_type' => 'post',
));
foreach( $pages as $post )
setup_postdata($post);
I'm doing this way but it doesn't work.
foreach( $pages as $post ) {
if ($post[0] % 3 == 0) {
setup_postdata($post.'<\div class="clearfix"\>');
}
else {
setup_postdata($post);
}
Share
Improve this question
edited Aug 29, 2017 at 17:00
Anton Lukin
8875 silver badges17 bronze badges
asked Aug 29, 2017 at 16:24
BufferOverrunBufferOverrun
111 bronze badge
1 Answer
Reset to default 1Try to update your second code part with
$count = 1;
foreach( $pages as $post ) {
setup_postdata($post);
// show your post here
if ($count++ % 3 === 0)
echo '<div class="clearfix"></div>';
本文标签: phpHow to add clearfix class according to to the posts number
版权声明:本文标题:php - How to add clearfix class according to to the posts number? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741644375a2390100.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论