0

I'm using flexslider with wp and my slider have 2 slides in view as one, the problem is when i have Steady number of slides i got one extra blank slide,also at that case my newest two slides goes to last position, and when i have odd then everything is fine.

<?php
$post_counter = wp_count_posts('news');
$numOfPosts = (int)$post_counter->publish;
$i = 1;?>  <div class="flexslider flexslider-wrapper " id="slide1">
<div class="row nav-contain">
        <h1>Title</h1>
        <div class="flex-nav-container">
            <div class="flex-nav">

            </div>
        </div><!-- /.flex-nav-container -->


        </div>
    <ul class="slides">
        <li>
        <?php
        query_posts(array(
        'showposts' => -1,
        'post_type' =>'news',
        'orderby' => 'publish_date',
        'order'   => 'DESC'
        ));

        if (have_posts()) : while (have_posts()) : the_post();

        ?>
            <div class="col-md-6">
                <div class="description">
                    <div class="item-title">
                    <a class="item-date"><?php echo get_the_date(); ?></a>
            <h1><a href="<?php the_permalink();?>"><?php echo mb_strimwidth( get_the_title(), 0, 40, '...' );?></a></h1>
                    </div>
                    <div class="exceprt">
                    <?php echo  the_excerpt(); ?>
                    </div>
                </div>
            </div>
        <?php
        $i++;

        if($i % 2 == 1 && $numOfPosts > 2){
            echo '</li><li>';
        }
        endwhile;endif;
        wp_reset_query();
        ?>

        </li>
    </ul>
</div>
<div class="clearfix"></div>

EDIT: Partial solution to this is animationLoop: false, in this way i get all well sorted, but problem is that i need to use animationloop, last slide still empty also i provide my js:

 $('#slide-1').flexslider({
    animation: "slide",
    controlsContainer: '#slide-1 .flex-nav',
    manualControls: '#slide-1 .flex-control-nav li',
    controlNav: false,
    slideshow: false,


});

REEDIT: When i remove animation:"slide", posts are in right orded (newest-oldest), but last slide stil empty.

2
  • query_posts should never be used and causes all manner of problems. Use WP_Query instead – Tom J Nowell May 4 '18 at 1:28
  • Thx for this @TomJNowell , will fix and avoid in future. – MR.Don't know May 7 '18 at 23:07
0

I solved issue with putting integer to -1,don't know really why this helped but if someone get same problem then maybe this will help to him.

<?php $i = -1;
 if (have_posts() ) : while ( have_posts() ) : the_post();
 if ($i%2 == 1) echo '</li><li>'; 
 ?>
1
  • it's because your loop adds an opening <li> tag at the end, and the math is off, so you'd end up with 1 extra li tag, depending on wether an even or an odd number of posts were fetched – Tom J Nowell May 4 '18 at 1:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.