Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-25-2011, 11:18 AM   PM User | #1
james.coutie
New to the CF scene

 
Join Date: Mar 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
james.coutie is an unknown quantity at this point
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!!
james.coutie is offline   Reply With Quote
Old 03-25-2011, 11:23 AM   PM User | #2
james.coutie
New to the CF scene

 
Join Date: Mar 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
james.coutie is an unknown quantity at this point
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++;
          }
    }
        
?>
james.coutie is offline   Reply With Quote
Old 03-25-2011, 04:54 PM   PM User | #3
tomws
Senior Coder

 
tomws's Avatar
 
Join Date: Nov 2007
Location: Arkansas
Posts: 2,644
Thanks: 29
Thanked 330 Times in 326 Posts
tomws will become famous soon enoughtomws will become famous soon enough
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?
tomws is offline   Reply With Quote
Reply

Bookmarks

Tags
gallery, navigation, photo

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:30 AM.


Advertisement
Log in to turn off these ads.