Posts: 11
Threads: 4
Joined: Mar 2011
Hi!
I want a gallery-script to fetch the page-slug in order to find a coresponding folder.
I'm quite noive at php-programming, so I'm sure it's an obvious solution.
However; this is where I need to get the page slug:
Code:
$images_dir = 'data/uploads/images/PAGE SLUG HERE/';
$thumbs_dir = 'data/uploads/images/PAGE SLUG HERE/thumbnails/';
So, how do I fix this?
Thanks in advance!
Posts: 1,108
Threads: 70
Joined: Aug 2009
Just use
Code:
$images_dir = 'data/uploads/images/'.get_page_slug(FALSE).'/';
$thumbs_dir = 'data/uploads/images/'.get_page_slug(FALSE).'/thumbnails/';
edit: fixed code
Posts: 11
Threads: 4
Joined: Mar 2011
Yhea, I've tried that, it only breaks the site.
Maybe got something to do with other parts of the script.
Code:
<?php
function make_thumb($src,$dest,$desired_width) {
$source_image = imagecreatefromjpeg($src);
$width = imagesx($source_image);
$height = imagesy($source_image);
$desired_height = floor($height*($desired_width/$width));
$virtual_image = imagecreatetruecolor($desired_width,$desired_height);
imagecopyresized($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height);
imagejpeg($virtual_image,$dest);
}
function get_files($images_dir,$exts = array('jpg')) {
$files = array();
if($handle = opendir($images_dir)) {
while(false !== ($file = readdir($handle))) {
$extension = strtolower(get_file_extension($file));
if($extension && in_array($extension,$exts)) {
$files[] = $file;
}
}
closedir($handle);
}
return $files;
}
function get_file_extension($file_name) {
return substr(strrchr($file_name,'.'),1);
}
$images_dir = 'data/uploads/images/PAGE SLUG HERE/';
$thumbs_dir = 'data/uploads/images/PAGE SLUG HERE/thumbnails/';
$thumbs_width = 200;
$images_per_row = 4;
$image_files = get_files($images_dir);
if(count($image_files)) {
$index = 0;
foreach($image_files as $index=>$file) {
$index++;
$thumbnail_image = $thumbs_dir.$file;
if(!file_exists($thumbnail_image)) {
$extension = get_file_extension($thumbnail_image);
if($extension) {
make_thumb($images_dir.$file,$thumbnail_image,$thumbs_width);
}
}
echo '<a href="',$SITEURL.$images_dir.$file,'" class="group" rel="gallery"><img src="',$SITEURL.$thumbnail_image,'" /></a>';
if($index % $images_per_row == 0) { echo '<div class="clear"></div>'; }
}
echo '<div class="clear"></div>';
}
else {
echo '<p>There are no images in this gallery.</p>';
}
?>
Posts: 1,108
Threads: 70
Joined: Aug 2009
Sorry it should be
Code:
$images_dir = 'data/uploads/images/'.get_page_slug(FALSE).'/';
$thumbs_dir = 'data/uploads/images/'.get_page_slug(FALSE).'/thumbnails/';
Posts: 11
Threads: 4
Joined: Mar 2011
Perfect
Thanks very much!