Separate 6 images in 3 div, forming a slider with bxslider

Asked

Viewed 162 times

1

I am using the plugin bxslider. Each slider contains 6 images that are divided into 3 div, whose classes are item_top and item_bottom, for three images from top and bottom, respectively. When I first picked up the static code, it was like this:

<ul>
    <li>
        <div class="item_top">
            <img src="image_1.jpg"/>
        </div>
        <div class="item_bottom">
            <img src="image_2.jpg"/>
        </div>
    </li>
    ...
    ...
</ul>

Every 3 li shape a slide. The problem is that I now bring these images from the database, so I can’t just add two div in each li because otherwise the images will come duplicated. So the code is like this now:

<ul>
    <li>
        <div class="">
            <img src="<?php echo $x['imagem']; ?>"/>
        </div>
    </li>
    ...
    ...
</ul>

I looked for solutions, and the best I found was to remove from HTML as li, engage with Javascript counting every 2 div, and then add the classes for each div odd and even. This way did not work as desired, because the plugin set the rules for div instead of li, and even adding via JS, there were problems.

I need help. If you wish, there is an example of static HTML in this website here, in the "Dealers and Resellers" area, to see how I need you to be visually, coming images from the database.

  • Let me get this straight, the problem is that through the database you can’t control whether it will come 3 straight or 2 in 2?

  • @Rboschini This. The way it is in my code, which is the second block shown, it just displays three images on one slide, and three more on the next. I need this second trio of images to be below the first. Currently each slide should contain 3 li, and within each, two div with the classes cited, however if it is necessary to modify the structure, and place three images by div, i believe that there will be no problems, I just need it to stay the way it is in the link I passed. :)

1 answer

0

By the link you passed from example, I suggest you create a field in your table to identify if the image is top or bottom and the return of the query would be:

<ul>
<?php foreach ($imagem as $x){ ?>
    <li>
      <?php if ($x['nome-do-campo'] == 'top'){ ?>
        <div class="item_top">
            <img src="<?php echo $x['imagem']; ?>"/>
        </div>
      <?php } else { ?>
        <div class="item_bottom">
            <img src="<?php echo $x['imagem']; ?>"/>
        </div>
      <?php }?>
    </li>
<?php } ?>
</ul>
  • Unfortunately it did not work very well because the condition will still display only one image in each div.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.