Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Joe Li
Joe Li
8,104 Points

PHP | USING A PLUG IN WITH LIGHTBOX

Hey Guys,

I was wondering if a PHP EXPERT could help me out!

I'm using a really cool plug-in https://mixitup.kunkalabs.com/ it basically splits my images into different categories.

I'm also using a lightbox that allows me to open up the image and then select the next image in the array.

The problem is, if I select into one folder, open up an image and try to slide to the next image it pulls the next image which isn't associated with that folder.

    <!-- Begin Portfolio -->
    <section id="section2">

        <div class="container portfolio">

            <!-- Page Title -->
            <div class="row page-title-2">
                <div class="col-lg-12">
                    <h3>Gallery</h3>
                    <hr>
                    <p>List of Our Projects</p>
                </div>
            </div>

            <!-- Gallery Filter -->
            <div data-scroll-reveal="enter left and move 50px over 1s" class="container text-center">
              <ul class="nav nav-pills">
                <li class="filter" data-filter="all">all</li>
                <li class="filter" data-filter="modern">Modern & Handless</li>
                <li class="filter" data-filter="bespoke">Traditional Bespoke</li>
                <li class="filter" data-filter="bedrooms">Bedrooms</li>
              </ul>
            </div> 

            <!-- Gallery Items -->
            <div class="container port-holder">
              <ul id="myPortfolio" class="no-padding">

                <?php 
                /*shuffle($images);*/ //Random Order
                foreach($images as $project_id => $image) { ?>

                    <li class="item <?php echo $image["class"]; ?> col-xs-4 no-padding">

                        <a  href='<?php echo $image["img-main"]; ?>' data-lightbox="example-set" data-title='<?php echo $image["text"]; ?>'>
                            <img class="example-image" src='<?php echo $image["img-thumb"]; ?>' alt=""/>
                            <span class="portfolio-hover">
                              <span>
                                <span class="portfolio-title"><?php echo $image["title"]; ?></span><br>
                                <span class="portfolio-category"><?php echo $image["description"]; ?></span>
                              </span>
                            </span>
                        </a>

                    </li>

                <?php } ?>

              </ul>
            </div>

        </div>

    </section>
    <!-- End Portfolio -->

Anyone got any ideas??

Thanks!

Joe

1 Answer

Hey Joe!

It sounds like all the stuff you have running over the top is javascript? I think your problem might be coming from mixing up front and back end sources..

My long-shot guess would be that - although you're sorting the images with javascript - this isn't rearranging the base-array you have in php? So the images maintain their order, even though they appear randomized on the front end. A good way to test for this is a lot of var_dump($array) -ing. You should be able to narrow it down pretty quickly by seeing how the php array is reacting.

If this is the case, you'll need to either sort the php array, or transfer the php array to a JSON format (which is essentially an array javascript can read and sort through), and source your pages from that.

You could also try ajax but generally speaking, I find that if you can get it to work without the javascript, it will be both unobtrusive and a lot easier to stick the javascript on top. Once everything is running smoother than my best chat-up line, I would then remove php elements and append javascript elements (using javascript) so it works in any situation.

I hope this helps!

Joe Li
Joe Li
8,104 Points

Hey Tom,

Thanks for your help, I really appreciate it! Will give what you said a go and let you know how I get on!

Cheers,

Joe