DISPLAYING IMAGE(S) FROM A MASTER IMAGE LIBRARY IN YOUR VIEWERS - Dec 29th, 2018
|
Here’s a way to use a master image library and not have to re-upload your images each time you want to use them.
It developed because user Deborah wanted to be able to select the specific logo(s) that were displayed on a set of detail pages from a database of previously uploaded logo images.
After a little help from Chris Waddell from Interactive Tools, here’s what Deborah came up with. I hope you find it useful.
SECTION EDITORS For this example you’ll need to create a multi-record editor called “Logo Uploads” with a “Title” text field for the name of the logo and an “Upload” field called “logos” for the logo images.
You’ll also have to create a multi-record editor called “Programs” where you’ll create your “products” records and decide which logos are to be shown on each product detail page.
In the “Programs” editor you’ll also need to create a multi value pull down (or checkbox) list field called “logos”.
For the “List Options” for this field, choose “Get options from database (advanced)”, Section Tablename: “logo_uploads”, Option Values: “num”, and Option Labels “title”.
For the Viewer URLs > detail page URL, enter /logotestdetail.php
After you’ve uploaded some “logos” and created some “product” records it’s time create your test list and detail viewers.
VIEWERS The list viewer will be called “logotestlist.php” and the detail viewer will be called “logotestdetail.php”
The list viewer is a standard viewer which you can create from the code generator for the “Programs” editor.
The detail viewer has a few modifications, but start with the standard detail viewer that’s generated by the code generator, and then at the top of the viewer, add the following code after the get records call:
<?php //display logos selected from list in other table, note both tables have same field name of 'logo' $numsTabbedList = $programsRecord['logo']; $numsTabbedList = trim($numsTabbedList); $numsCommaList = str_replace("\t", ",", $numsTabbedList); if ($numsCommaList) { list($logo_uploadsRecords,) = getRecords(array( 'tableName' => 'logo_uploads', 'where' => "num IN ($numsCommaList)", 'allowSearch' => '0', )); } else { $logo_uploadsRecords = array(); // empty array } ?>
And in the body of the viewer where you want your logos to appear, add this code (page styling is up to you):
<?php foreach($logo_uploadsRecords as $logo_uploadsRecord): ?> <?php foreach ($logo_uploadsRecord['logo'] as $upload): //display logos selected from list in logo_uploads table ?> <img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><?php endforeach ?> <?php endforeach ?>
You can download a set of ini.php files and a list and detail viewer from:
http://www.thecmsbcookbook.com/downloads/logos.zip
Sorry, you'll have to supply your own images.
** DON’T FORGET TO CHANGE THE “LOAD VIEWER LIBRARY - $dirsToCheck PATH IN THE VIEWERS TO YOUR SERVER PATH.
After you’ve got the example working, you can add any required fields and style the pages the way you’d like.
|
The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact
Interactive Tools for information on the downloading of the software or the purchasing of licenses.