March 16, 2004
Simple sequential navigation with php
I was thinking recently about a problem some photographers have asked me about when they build their personal photo sites and have large groups of pages sequentially numbered with a single image and a next and back button on each. I sucks to have to edit each page to go to the next link and back page, when you start to have 50+ pages, even 10 is less than fun.
I know very little about PHP, but try to learn when I need to know more, so excuse me for the logic errors in what I am posting (and please tell me where they are!) I burned up google looking for this type of solution and could find nothing so direct. I suspect because it is so simple that most people who know PHP would do it with out thinking about, and PHP is open source so there is SO much content online it is hard to narrow it down to such a simple usage example.
All you have to do add this PHP to your page, and duplicate the page as for as many images you have. Naming the pages sequentially and the images the same way. (1.html, 2.html, 3.html.... and /images/1.jpg, 2.jpg, 3.jpg.... and such), and done.
--------------
In the Head:
--------------
Establish the variables in the head of the doc.
Setup a variable like "$thisPage" and make that variable set itself by seeing what the file name is and removing the file extension, in this case .html
<?php $page=$_SERVER["PHP_SELF"]; $thisPage = basename($page, ".html"); $a="1"; ?>
</head>
So if your file is at www.domain.com/photo/1.html
This will set these valuables:
$page = /photo/1.html
$thisPage =1
--------------------------
In the actual content:
--------------------------
Use the established "$thisPage" for all the references to the next and back links and linking to the image.
The image is the same as the page number:
Next link:
Back Link:
This is image/page number:
Again, then all you have to do is duplicate the page as for as many images you have, naming the pages sequentially and the images the same way. (1.html, 2.html, 3.html.... and /images/1.jpg, 2.jpg, 3.jpg.... and such), and the pages to the work, you may have to set the 1st and last page to link to eachother, and done.


Comments
That is pretty slick!
Posted by: Jake of 8bitjoystick.com | March 18, 2004 09:29 AM
Hey, I haven't had a chance to test your gallery system yet, but I just wanted to let you know a couple systems that worked for me.
The first is straight out of Webmonkey: PHP Gallery. An example of my implementation: Golden Retriever puppies
It is a photo gallery run with two PHP files, a text file listing the image names, a directory with the pictures and a directory containing the thumbnails. The first PHP file arrays a number of thumbnails you choose with links to the full size image. The link points to the second PHP file that is essentially a pop up displaying the full size image. You can have hundreds of images or one image and the "previous" and "next" buttons to browse the gallery are all handled automatically. Essentially, one file dynamically handles your entire gallery of images.
The second is a javascript based gallery. I found it here. I have used it here. The html file has the javascript in it. You just let it know the names of the directories containing your files which in each directory must be numbered 1.jpg, 2.jpg...etc. One file dynamically displaying many images, very nice.
I'll try your version soon.
Posted by: Jonathan | March 18, 2004 11:51 AM
Thanks Jonathan, those are both more complete solutions than mine I think, and great resources. I will have to try them out next time it comes up.
Posted by: anthony | March 22, 2004 09:30 AM