Sunday, December 6, 2009

How to add a photo gallery using PHP

phpscript A PHP enhanced photo album script that automates retrieval of all images within a specific directory to show with pagination links to cycle through each page. The script is placed within a desired image directory that automatically derives the file names of all images within it and creates a JavaScript array for further processing. As you upload or modify images within the directory, the script will automatically adapt and allows you to update your gallery with ease.

Click here to see the demo

Steps to follow:

1. Login to your Blogger Dashboard and navigate to Layout > Edit HTML

2. Insert the following section code below right after this section code here: ]]></b:skin>

<script type="text/javascript" src="http://www.mysite.com/myimages/getalbumpics.php?id=templates"></script>

<script type="text/javascript">
//Optional, manual description for particular pictures inside album
//Syntax: albumid.desc[index]="Picture description here"
//eg: templates.desc[2]="This is description for the 3rd picture in the album"
//eg: templates.desc[6]="This is description for the 7th picture in the album"
</script>

<script type="text/javascript" src="ddphpalbum.js">
/*********************************************
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ *********************************************/
</script>

<link rel="stylesheet" type="text/css" href="ddphpalbum.css" />

Note: The above references getalbumpics.php, ddphpalbum.js, and ddphpalbum.css files. In which you will need to right click and save to upload to your own server. Keep in mind that you will need to add the .php file in a separate folder, the folder where your album images are located.

Configuration for the above section code

- The section code in blue that is underlined should be changed to the link where you PHP script and album images are located. At the end of the link, you see “templates”, this is the name of your folder and should be modified to fit yours. *Words not underlined should not be modified.

- The words in green is your folder name, where your script and images are located.

- Numbers in red represents image order and words in bold is your picture description, which can be modified.

3. Navigate over to Page Elements under the Layout tab to add an HTML/JavaScript gadget and copy/paste the following section code below in the box.
<script type="text/javascript">

new phpimagealbum({
    albumvar: templates, //ID of photo album to display (based on getpics.php?id=xxx)
    dimensions: [2,5],
    sortby: ["file", "asc"], //["file" or "date", "asc" or "desc"]
    autodesc: "", //Auto add a description beneath each picture? (use keyword %i for image position, %d for image date)
    showsourceorder: false, //Show source order of each picture? (helpful during set up stage)
    onphotoclick:function(thumbref, thumbindex, thumbfilename){
        thumbnailviewer.loadimage(thumbref.src, "fit2screen")
    }
})

</script>
Configuration for the above section code

- Under albumvar: – change “templates” to that of your folders name containing the script and images

- Dimensions: 2 = columns and 5 = rows, these numbers should be modified to fit your template.

** Tutorial completed

No comments:

Post a Comment