Carousel uneven when there aren’t equal number of posts

If I don’t have 8 posts the carousel looks like this. enter image description here

Here is the WordPress loop

Read More
                <div class="section-title">
                    <h1>Most Recent Post</h1>
                </div>                  
                <div id="recent-post-carousel" class="carousel slide" data-ride="carousel">
                    <ol class="carousel-indicators">
                        <li data-target="#recent-post-carousel" data-slide-to="0" class="active"></li>
                        <li data-target="#recent-post-carousel" data-slide-to="1"></li>

                    </ol>
                    <div class="carousel-inner">










                   <?php
                    // Get posts (tweak args as needed)
                    $i=0;
                    $args = array(
                        'post_type'        => 'post',
                        'posts_per_page'   => -1,
                        'orderby' => "date",
                        'order' => "desc"
                    );
                    $posts = get_posts( $args );
                ?>

                <?php foreach (array_chunk($posts, 4, true) as $posts) :  ?>
                <div class="item <?php if ($i==0){echo 'active';}?>">            
                    <div class="row">

                        <?php foreach( $posts as $post ) : setup_postdata($post); ?>

                           <div class="col-sm-6">
                                    <div class="single-post">
                                        <div class="pull-left post-image">
                                            <a href="#">
                                                <?php the_post_thumbnail( 'full' );  ?>
                                                <i class="fa fa-angle-right"></i>
                                            </a>
                                        </div>
                                        <div class="pull-right post-details">
                                            <p class="post-date">03 Dec 2014</p>
                                            <p><?php echo $i?></p>

                                            <a href="#"><h5><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
                            </h5></a>
                                            <span>John doe</span>
                                            <p><?php echo substr(get_the_excerpt(), 0,99).' [...]'; ?></p>
                                        </div>
                                    </div>
                                </div>
                        <?php $i++ ?>

                        <?php endforeach; ?>

                    </div>

                        </div>

                <?php endforeach; ?>










                    </div>
                </div>
            </div>

Not sure if it has something to do with wordpress, i tried it on a static page and it worked fine. one way to fix it is to remove left or right margin from the col-sm-6, but i don’t think this is a good way to do things.

Related posts

1 comment

  1. I have created a fiddle for you. In fiddle above one is your case and the below one is Case with min-height(solved).

    **https://jsfiddle.net/Anuj_Kumar/L5uduxLr/1/embedded/result/**
    

    If still it’s not fixed then try adding class “cleafix” with “single-post”.

Comments are closed.