|
#1
|
|||
|
|||
|
Wrap Thumbnails / Category List (PHP Help)
Need some PHP help:
1) How can I "count" the thumbnails, and add a BR tag after every 4th one? I know I could make them wrap with CSS, but for my purposes I need it done in the PHP. Code:
if($_GET['x'] == "") {
$thumb_output = "";
$where = "";
if($_GET['category'] != "") { $where = "and (category='".$_GET['category']."')"; }
$query = mysql_query("select category,id,headline,image from ".$pixelpost_db_prefix."pixelpost where (datetime<='$cdate') $where order by datetime desc");
while(list($image_category,$id,$title,$name) = mysql_fetch_row($query)) {
$title = pullout($title);
$thumbnail = "thumbnails/thumb_$name";
$thumb_output .= "<a href='$PHP_SELF?showimage=$id&x=image&category=$image_category'><img src='$thumbnail' alt='$title' title='$title' class='thumbnails' /></a>";
}
$tpl = ereg_replace("<THUMBNAILS>",$thumb_output,$tpl);
}
|
|
#2
|
|||
|
|||
|
You can add a $counter variable within the while loop to increment each time. Then add an if ($counter == 4), output the <br> and also reset the $counter.
|
|
#3
|
|||
|
|||
|
Okay, I'm really close! I'm now trying a modification to a different section of the Pixelpost code (see below).
I basically want a list of links above the photo, and a list of thumbnails below the photo. These lists should be ALL the other photos from the same category as the photo you are viewing. I have altered the code that runs the <IMAGE_THUMBNAIL_ROW> tag, and also added <IMAGE_LINK_ROW>. Currently, these tags only display a link/thumbnail to the image you are currently viewing. I need to figure out how to get it to display the "ahead_thumbs" and the "behind_thumbs". I tried adding "where (category == '$image_category')", but it's not working. Anyone want to help me finalize this? Code:
if(function_exists(gd_info)) {
$gd_info = gd_info();
if($gd_info != "") { // check that gd is here before this
// thumbnail row, 5 thumbs
$aheadnumb = mysql_query("select count(*) as count from ".$pixelpost_db_prefix."pixelpost where (datetime > '$image_datetime') and (datetime<='$cdate')");
$aheadnumb = mysql_fetch_array($aheadnumb);
$aheadnumb = $aheadnumb['count'];
$behindnumb = mysql_query("select count(*) as count from ".$pixelpost_db_prefix."pixelpost where (datetime < '$image_datetime') and (datetime<='$cdate')");
$behindnumb = mysql_fetch_array($behindnumb);
$behindnumb = $behindnumb['count'];
$aheadlimit = round(($cfgrow['thumbnumber']-1)/2);
$behindlimit = round(($cfgrow['thumbnumber']-1)/2);
if($aheadnumb <= "1") {
$behindlimit = ($cfgrow['thumbnumber']-1)-$aheadnumb;
$aheadlimit = $aheadnumb;
}
if($behindnumb <= "1") {
$aheadlimit = ($cfgrow['thumbnumber']-1)-$behindnumb;
$behindlimit = $behindnumb;
}
$totalthumbcounter = 0; // will count up to four no matter what
$ahead_thumbs = "";
$thumbs_ahead = mysql_query("select category,id,headline,image from ".$pixelpost_db_prefix."pixelpost where (category == '$image_category') and (datetime<='$cdate') order by datetime asc limit 0,$aheadlimit");
while(list($image_category,$id,$headline,$image) = mysql_fetch_row($thumbs_ahead)) {
list($local_width,$local_height,$type,$attr) = getimagesize("thumbnails/thumb_$image_name");
$ahead_thumbs .= "<a href='$PHP_SELF?showimage=$id'><img src='thumbnails/thumb_$image' alt='$headline' title='$headline' class='thumbnails' width='$local_width' height='$local_height' /></a>";
$ahead_links .= "<a href='$PHP_SELF?showimage=$id'>$headline</a>";
$totalthumbcounter++;
}
$behind_thumbs = "";
$thumbs_behind = mysql_query("select category,id,headline,image from ".$pixelpost_db_prefix."pixelpost where (category == '$image_category_id') and (datetime<='$cdate') order by datetime desc limit 0,$behindlimit");
while(list($image_category,$id,$headline,$image) = mysql_fetch_row($thumbs_behind)) {
list($local_width,$local_height,$type,$attr) = getimagesize("thumbnails/thumb_$image_name");
$behind_thumbs = "<a href='$PHP_SELF?showimage=$id'><img src='thumbnails/thumb_$image' alt='$headline' title='$headline' class='thumbnails' width='$local_width' height='$local_height' /></a>$behind_thumbs";
$behind_links = "<a href='$PHP_SELF?showimage=$id'>$headline</a>$behind_links";
}
list($local_width,$local_height,$type,$attr) = getimagesize("thumbnails/thumb_$image_name");
$thumbnail_row = "$behind_thumbs<a href='$PHP_SELF?showimage=$image_id'><img src='thumbnails/thumb_$image_name' alt='$image_title' title='$image_title' class='current_thumbnail' width='$local_width' height='$local_height' /></a>$ahead_thumbs";
$link_row = "$behind_links<a href='$PHP_SELF?showimage=$image_id&x=image&category=$image_category_id'>$image_title</a> | $ahead_links";
$tpl = ereg_replace("<IMAGE_THUMBNAIL_ROW>",$thumbnail_row,$tpl);
$tpl = ereg_replace("<IMAGE_LINK_ROW>",$link_row,$tpl);
} // gd_info()
} // func exist
|
| Post Reply |
| Thread Tools | |
|
|