Uploads Per Page
Is there a way to get uploads limited per per page?
For example, a client is using CMSB as a gallery subscription website. Each album can have 500 to 1000 pictures. I would like get the pictures to display about 50-100 per page instead of trying to load all of them at the same time. I don't think I have ever done this, so I am needing some help.
Thanks in advance
Ok, sure. Is an album a single record in the CMS? So there's a single record in the CMS with an upload field that has 500-1000 uploads? Is that correct?
It's a multi-record section and each record is a separate gallery. Each gallery will have 500+ uploads
Yes, this is quite possible. You can use the following getRecords() call to fetch the uploads limited by the perPage value. It will need to be placed below the getRecords() call that returns the gallery record:
list($uploadRecords, $uploadMetaData) = getRecords(array(
'tableName' => 'uploads',
'perPage' => 50,
'where' => 'tableName = "gallery" AND recordNum = "' . $galleryRecord['num'] . '"',
'allowSearch' => false,
'loadUploads' => false,
Note that the above is an example and may need to be modified to suit your case; particularly the "gallery" table name and the $galleryRecord variable name.
The created variables are:
- $uploadRecords will contain the array of records for the current page. You can likely substitute this into the existing loop you are using to output the images.
- $uploadMetaData will contain data related to the pagination. The following values can be used to provide basic pagination links:
Let me know if this suits your needs, or if you have any further questions.
I think that this line:
'where' => 'tableName = "chs_galleries" AND recordNum = "' . $gallery_imagesRecord['num'] . '"',
'where' => 'tableName = "chs_galleries" AND recordNum = "' . $chs_galleriesRecord['num'] . '"',
Give that a shot and see if that helps.
I have a couple more things to try:
1) Can you change 'loadUploads' to false in your first getRecords() call;
2) Can you also change this line:
<?php foreach ($uploadRecords['gallery_images'] as $index => $upload): ?>
<?php foreach ($uploadRecords as $index => $upload): ?>
If that still doesn't help, can you check the Developer Log in CMSB (under Admin Menu) and let me know if there are any additional errors being logged there?
That works except I have had to add to the link it generates. Where does this variable get defined?
<img src="/webadmin/uploads/<?php echo htmlencode($upload['thumbUrlPath']) ?>" class="img-fluid" alt="<?php echo htmlencode($chs_galleriesRecord['gallery_title']) ?>">
To dynamically generate the upload directory (the portion you bolded), you can add this code below your getRecords() calls:
$schema = loadSchema('chs_galleries');
list($uploadDir,$uploadUrl) = getUploadDirAndUrl($schema['gallery_images']);
$uploadUrl should now contain the directory the images are in. You can then change your image src to:
src="<?php echo $uploadUrl . htmlencode($upload['thumbUrlPath']) ?>"
Let me know if that solves the issue, or if I can help with anything else.