Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question PHP Photo Gallery Navigation

    I'm trying to add some extra navigation to our website's photo galleries. Currently from the gallery page users simply go into photos and back out to the gallery again. I would like to build in next and previous links, but can't work out how to do this without a complete rebuild of the galleries.

    Here's the coding for the gallery page:
    PHP Code:
    <?php

        
    // The Gallery of Images
        
        
    $dirname "images/hostschemesm/"
        
    $images scandir($dirname);
        
    $ignore = Array("."".."".htaccess");

        foreach(
    $images as $curimg)
        {
            if (!
    in_array($curimg$ignore))
            {
                  echo 
    "<a href='view1.php?img=$curimg'><img src='images/hostschemesm/$curimg' title='$curimg' alt='$curimg' width='200' height='134'  /></a>";
              }
        }
        
    ?>
    and the photo viewing page:
    PHP Code:
    <?php

        
    // View an Image
        
        
    $curimg=$_GET['img'];
        
        echo 
    "<a href='1.php'><img src='images/hostschemelg/$curimg' title='$curimg' alt='$curimg' width='744' /></a>";
        
    ?>
    I'm thinking it possible to just edit the photo viewing page to scandir($dirname) to be able to create a list of contents again, but I don't have the PHP skills to write this myself yet. I'm hoping to be able to either make it loop around (last photo links to first again) or preferably have the buttons disappear if there is no link in that direction.

    Any help would be appreciated and if you can explain to me how things work too that would be AMAZING!!

    Thanks!!

  • #2
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Reversing Gallery Order

    Also, the directory of galleries uses the code below, I was wondering if anyone knew a simple way to reverse the order that the galleries are displayed so the most recent I put on goes to the top?

    Thanks!!

    PHP Code:
    <?php

        
    // The Gallery of Images
        
        
    $dirname "index-photos/"
        
    $images scandir($dirname);
        
    $ignore = Array("."".."".htaccess");
        
    $index 1;

        foreach(
    $images as $curimg)
        {
            if (!
    in_array($curimg$ignore))
            {
                  echo 
    "<a href='$index.php'><img src='index-photos/$curimg' width='400' alt='$curimg' /></a>";
                
    $index++;
              }
        }
            
    ?>

  • #3
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by james.coutie View Post
    I'm thinking it possible to just edit the photo viewing page to scandir($dirname) to be able to create a list of contents again, but I don't have the PHP skills to write this myself yet.
    What do you mean you can't write it yourself? The starter code is already there in the code provided and copy/paste is fairly easy. The result is an array. From that, you could determine the previous and next images by finding the current filename. The PHP array functions documentation should get you started.

    FWIW, there are loads of pre-built image galleries that would work better than this and provide a nice javascripty lightbox. A "complete rebuild" shouldn't be a major project if this is the extent of the gallery code.
    Are you a Help Vampire?


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •