I have created a dynamic category slider across my wordpress website, the slider grabs content via the category slugs. I have it implemented across multiple categories, however one category I implement it and it shows the exact same content x2. So, I limit to pull in content 8 times, as you’ll see below, it is showing 16! Any suggestions?

<div class="on_page_sliders">
<div id='mySwipe' style='max-width:603px; height: 250px; margin:0 auto' class='swipe'>
    <div class='swipe-wrap'>
        <?php
        $strategy2_featurepost_category_id = get_cat_ID('strategystrategy_featurepost');
        $carouselItems = array();
        $postIndex = 0;
        $nbPostPerSlide = 8;
        query_posts('category_name=strategystrategy&cat=-'.$strategystrategy_featurepost_category_id.'&posts_per_page=-1');
        if ( have_posts() ) while ( have_posts() ) : the_post();
            $postIndex ++;
            $carouselItems[] = $post->ID;
            ?>
            <?php
            /**
             * open the div slide
             */
            ?>
            <?php if($postIndex === 1):?>
                <div>
            <?php endif; ?>
                <div class="pul_leftt">
                <a class="pull-leftt" href="<?php the_permalink(); ?>">
                    <span class="p_title">
                    <?php the_titlesmall('', '', true, '') ?>
                    </span><br>
                    <span style="color: #444 !important; font-size:12px;" class="excerpt">
                    <?php echo excerpt(15); ?>
                    </span>                 
                    <br>
                </a>
                </div>
            <?php
            /**
             * close the div slide when reaching $nbPostPerSlide
             */
            ?>
            <?php if($postIndex >= $nbPostPerSlide): $postIndex = 0; ?>
                </div>
            <?php endif; ?>
        <?php endwhile; ?>
        <?php wp_reset_query(); ?>
        <?php
        /**
         * close the div after the loop
         */
        ?>
        <?php if($postIndex && $postIndex < $nbPostPerSlide): ?>
            </div>
        <?php endif; ?>
    </div>
</div>
<nav>
    <ul class="nav_sp">
        <?php foreach($carouselItems as $index => $item): ?>
            <li><?php echo $index; ?></li>
        <?php endforeach; ?>
    </ul>
</nav>
<div style='text-align:center;padding-top:20px;'>
   <!-- <button class="arrow_leftt" onclick='mySwipe.prev()'><img src="./wp-content/uploads/2014/12/left_arrow.png" class="arrowz"></button>
    <button class="arrow_rightt" onclick='mySwipe.next()'><img src="./wp-content/uploads/2014/12/right_arrow.png" class="arrowz"></button> -->
</div>
</div>

Read more here: dynamic category slider (WP) categories showing twice in some browser


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: