Two problems when setting up a photo gallery
8 posts by 2 authors in: Forums > CMS Builder
Last Post: August 18, 2011 (RSS)
It often happens that when I write an article, I end up uploading 10+ pictures. One of those pictures ends up in the body of my article and the rest as thumbnails in a menu on the side. The problems I have are with the thumbnail images. The first thing is that the picture I use in the article body also ends up in the gallery, although I don't want it to. The second is that when I upload 6+ images, the menu becomes too crowded. I'd rather show 6 and add a "next page link" to show the rest.
To start off, here's my code at the top:
list($articlesRecords, $articlesMetaData) = getRecords(array(
'tableName' => 'articles',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$articlesRecord = @$articlesRecords[0]; // get first record
list($categoryRecords,$categoryMetaData) = getRecords(array(
'tableName' => 'categories',
));
$numToName=array();
foreach($categoryRecords as $record){
$numToName[$record['num']]=$record['name'];
}
foreach($articlesRecords as $thumbnails){
};
list($thumbnailsRecords,$thumbnailsMetaData) = getRecords(array(
'tableName' => 'articles',
'offset' => 1
));
The gallery code:
<div id="gallery">
<table>
<tr>
<?php foreach ($thumbnails['images'] as $upload): ?>
<td>
<div id="crop">
<a href="<?PHP echo $upload['urlPath'] ?>">
<img src="<?php echo $upload['thumbUrlPath'] ?>" />
</a>
</div>
</td>
<?php $maxCols=2; if (@++$count % $maxCols == 0): ?></tr>
<tr><?php endif; ?>
<?php endforeach; ?>
</tr>
</table>
</div>
Thanks in advance for any help offered!
Re: [Hansaardappel] Two problems when setting up a photo gallery
By Jason - August 15, 2011
Since all images are stored in a separate uploads table, it's possible to get those records directly using a separate query and set them to only show X per page.
You can try something like this:
list($articlesRecords, $articlesMetaData) = getRecords(array(
'tableName' => 'articles',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$articlesRecord = @$articlesRecords[0]; // get first record
// get image records
list($imageRecords, $imageMetaData) = getRecords(array(
'tableName' => 'uploads',
'allowSearch' => false,
'perPage' => 6,
'where' => "tableName = 'articles' AND fieldName = 'images' AND recordNum = '".intval($articlesRecord['num'])."'",
));
You can then treat $imageRecords like you would a regular record set.
Hope this helps get you started.
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Two problems when setting up a photo gallery
Thanks for your reply. Unfortunately it gives me the following notice (and it messes up my design):
Notice: Undefined index: listPageOrder in C:\xampp\htdocs\xampp\cmsAdmin\lib\viewer_functions.php on line 54
Any suggestions?
Thanks!
Re: [Hansaardappel] Two problems when setting up a photo gallery
By Jason - August 16, 2011
I think we need to stop getRecords from attempting to search for uploads, since we're already searching the uploads table.
Try this:
// get image records list($imageRecords, $imageMetaData) = getRecords(array(
'tableName' => 'uploads',
'allowSearch' => false,
'perPage' => 6,
'where' => "tableName = 'articles' AND fieldName = 'images' AND recordNum = '".intval($articlesRecord['num'])."'",
'loadUploads' => false,
'loadCreatedBy' => false,
));
Hope this helps
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Two problems when setting up a photo gallery
I just tried your suggestion, but unfortunately without succes. I get exactly the same notice and not the desired effect. Here's my current "body code"... is anything wrong with it?
<?php foreach ($imageRecords as $image): ?>
<?php if ($image['images']): ?>
<div id="content_menu_content">
<div id="content_menu_navbar">
<img src="picture-gallery.png" />
Photo Gallery</div>
<div id="gallery">
<table>
<tr>
<?php foreach ($image['images'] as $upload): ?>
<td>
<div id="crop">
<a href="<?PHP echo $upload['urlPath'] ?>">
<img src="<?php echo $upload['thumbUrlPath'] ?>" />
</a>
</div>
</td>
<?php $maxCols=2; if (@++$count % $maxCols == 0): ?></tr>
<tr><?php endif; ?>
<?php endforeach; ?>
</tr>
</table>
</div>
</div>
<p></p>
<?php endif ?>
<?php endforeach; ?>
Any other suggestions? I've searched around the forums quite a bit, but that didn't help me any further either.
Thanks again :)
Re: [Hansaardappel] Two problems when setting up a photo gallery
By Jason - August 17, 2011
To get rid of the notice, we need to set an orderBy option in getRecords.
Try this:
// get image records
list($imageRecords, $imageMetaData) = getRecords(array(
'tableName' => 'uploads',
'allowSearch' => false,
'perPage' => 6,
'where' => "tableName = 'articles' AND fieldName = 'images' AND recordNum = '".intval($articlesRecord['num'])."'",
'loadUploads' => false,
'loadCreatedBy' => false,
'orderBy' => "`order`",
));
Give this a try and let me know if this works for you.
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Two problems when setting up a photo gallery
Notice: Undefined index: images in C:\xampp\htdocs\xampp\cmsbuilder\articles4.php on line 150
Re: [Hansaardappel] Two problems when setting up a photo gallery
By Jason - August 18, 2011
There won't be an "images" field in the $imagesRecords record set because we are referencing the uploads table directly, we'll only have access to uploads fields.
Try this code instead:
<?php if ($imageRecords): ?>
<div id="content_menu_content">
<div id="content_menu_navbar">
<img src="picture-gallery.png" />
Photo Gallery</div>
<div id="gallery">
<table>
<tr>
<?php foreach ($imageRecords as $upload): ?>
<td>
<div id="crop">
<a href="<?PHP echo $upload['urlPath'] ?>">
<img src="<?php echo $upload['thumbUrlPath'] ?>" />
</a>
</div>
</td>
<?php $maxCols=2; if (@++$count % $maxCols == 0): ?>
</tr><tr>
<?php endif; ?>
<?php endforeach; ?>
</tr>
</table>
</div>
</div>
<p></p>
<?php endif ?>
Hope this helps
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/