Create list of categories from upload fields' info field

4 posts by 2 authors in: Forums > CMS Builder
Last Post: March 24, 2013   (RSS)

By benedict - March 17, 2013

Hi guys,

I am just populating an XML file for a gallery using data from CMSB.

Everything is working fine in terms of showing all the listings from a single viewer, and when clicked showing an enlarged version (My Gallery is the section name, 'images' is the upload field that contains all the images). My problem is this.

The gallery groups images that have the same category name (I am using 'info2' for each image). At the top of the XML page, it annnounces the category names, but I don;t know how to do this dynamically as I only want to list the category once, not 20 times.

Here is my code, with the categories hard-coded - is there some kind of loop I can do, that goes through all the info2 fields it finds and then spits out each category name once in a list?

<?php echo('<?xml version="1.0" encoding="utf-8"?>'); ?>
<?php 
  // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('/home/stockw/public_html/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

  // load record from 'my_gallery'
  list($my_galleryRecords, $my_galleryMetaData) = getRecords(array(
    'tableName'   => 'my_gallery',
    'where'       => '', // load first record
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $my_galleryRecord = @$my_galleryRecords[0]; // get first record
  if (!$my_galleryRecord) { dieWith404("Record not found!"); } // show error message if no record found

?>
<portfolio>
<!--Here is where I need to create my list of categories-->
    <categories>
        <category id="doncaster">Doncaster</category>
        <category id="bhs">Box Hill South</category>
        <category id="hawthorn">Hawthorn East</category>
        <category id="aspendale">Aspendale</category>
        <category id="templestowe">Templestowe</category>
        <category id="doncaster2">Doncaster</category>
    </categories>
    <items>
    <?php foreach ($my_galleryRecord['images'] as $index => $upload): ?>
            <item>
                <thumbnail><?php echo $upload['thumbUrlPath'] ?></thumbnail>
                <preview><?php echo $upload['urlPath'] ?></preview>
                <category><?php echo $upload['info2'] ?></category>
                <description><?php echo $upload['info3'] ?></description>
            </item>
        <?php endforeach ?>
    </items>
</portfolio>

By benedict - March 20, 2013

Anybody have any idea on this?

By benedict - March 24, 2013

Thanks Greg, that worked beautifully.