Adding description tag to PHP image gallery
I am trying add a descriptive tag under each image but most of the code is in PHP and i am not to familiar with how to program it without screwing up the whole structure. Here is开发者_运维知识库 the website: http://suncoastdeck.com/index.php?page=portfolio&start=0
Here is the code for the portfolio page:
<div class="content-box">
<?
//total number of images
$total = 77;
//max number of thumbnails per page
$max = 9;
//what image do we want to start from?
$startcount = $_GET["start"];
//if there is not a defined starting image, we start with the first
if(empty($startcount))
{
$startcount = 0;
}
//start off the loop at 1
$loop = 1;
//start the loop
while($loop <= $max)
{
//for the picture labels
$num = $startcount + $loop;
if($num > $total)
{
$num = $num - 1;
break;
}
// Add class="last" to every third list item
if(is_int($num / 3))
{
$last = ' class="last"';
}
else
{
$last = "";
}
//the code for the image
echo '
<li'.$last.'><a href="images/portfolio/pic-'.$num.'.jpg" rel="milkbox[gall1]"><img src="images/portfolio/thumbs/pic-'.$num.'-thumb.jpg" width="256" height="138" alt="Thumbnail of image '.$num.'" /></a><div>'.$num.'</div></li>';
//add 1 to the loop
$loop++;
}
echo '</ul>';
//Calculate the number of pages
$total_pages = $total / $max;
//clean it up
if(!is_int($total_pages))
{
$total_pages = floor($total_pages) + 1;
}
//start the page count at 1
$ploop = 1;
echo '<hr /><div id="portfolio-wrap"><div id="pages">Page: ';
while($ploop <= $total_pages)
{
$offset = ($ploop * $max) - $max;
if($startcount == $offset)
{
echo '<span>'.$ploop.'</span>';
}
else
{
echo '<a href="index.php?page=portfolio&start='.$offset.'">'.$ploop.'</a>';
}
$ploop++;
}
echo '</div>';
echo '<div id="portfolio-foot-left"><p>Displaying Images <strong>'.($startcount + 1).' - '.$num.'</strong> of <strong>'.$total.'</strong></p></div></div>';
?>
Pretty much what i want is to make section drop down a bit more where i can add in additional info about the pic. Any suggestions?
You need a database or else you can store your descriptions in a text file next to the image. What have you tried so far?
Basically you need to create a form that accepts the image name and caption, take the caption and write it to a file or database. Then when displaying the caption, you just add a <div>
that reads from file with file_get_contents()
. Why don't you copy the script to another directory and start experimenting? People probably won't write the whole thing for you ;)
精彩评论