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 20, 2013

Anybody have any idea on this?

By gregThomas - March 21, 2013

Hi,

Sorry for the delay in reply, I think this is the easiest way to loop through your categories:

<?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

  //Create the array that will store the images
  $categoryArray = array();

  //Cycle through the images.
  foreach($my_galleryRecord['images'] as $image){
    //If the description isn't already in the category array
    if(!in_array($image['info2'], $categoryArray)){
     //Add the description to the category array
      $categoryArray[] = $image['info2'];
    }
  } 

  //Sort the items into alphabetical order
  sort($categoryArray);

?>

<portfolio>
<!--Here is where I need to create my list of categories-->
    <categories>
        <?php foreach($categoryArray as $category): ?>
          <category id="<?php echo strtolower($category); ?>"><?php echo $category; ?></category>
        <?php endforeach; ?>
    </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>

This is just example code, so you might need to make a few changes to get it working. 

So the code cycles through each image array and stores the info2 field into a category array if its value isn't already stored in there. 

Then the code loops through the category array to create the categories list.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By benedict - March 24, 2013

Thanks Greg, that worked beautifully.