COMBO Page... kinda

5 posts by 2 authors in: Forums > CMS Builder
Last Post: March 25, 2014   (RSS)

By Daryl - March 24, 2014

Hi Tim,

Yes, we can easily achieve that by replacing the left list with the category list from the records and add a link parameter, i.e. ?category=1 and use the parameter value to determine which records will be displayed on the right list.

Here's an example of what I would do:

<?php
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('W:/test/htdocs/','','../','../../','../../../');
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 records from 'products_listing'
list($products_listingRecords, $products_listingMetaData) = getRecords(array(
  'tableName'   => 'products_listing',
  'loadUploads' => true,
  'allowSearch' => false,
));

// get the list of categories as array wherein the array key is the category value, and array value is the category label
// $productCategoriesValuesToLabels will be used for the left category list
$productCategoriesValuesToLabels = array_combine(array_pluck($products_listingRecords, 'category'), array_pluck($products_listingRecords, 'category:label'));

// $productsListsRecords will be used for the right sub-list
$productsListsRecords = array();
if (@$_REQUEST['category']){
  $productsListsRecords = array_groupBy($products_listingRecords, 'category', true);
  $productsListsRecords = @$productsRecords[$_REQUEST['category']];
}

?>

<!--left category list-->
<?php if (@$productCategoriesValuesToLabels ): ?>
  <?php foreach ($productCategoriesValuesToLabels  as $value => $label): ?>
  <a hef="?category=<?php echo htmlspecialchars($value); ?>"><?php echo htmlspecialchars($label); ?></a>
  <?php endforeach; ?>
<?php endif; ?>

<!--right category list-->
<?php if (@$productsListsRecords): ?>
  <?php foreach ($productsListsRecords as $product): ?>
  <a hef="<?php echo htmlspecialchars($product['_link']); ?>"><?php echo htmlspecialchars($product['title']); ?></a>
  <?php endforeach; ?>
<?php endif; ?>

Hope this helps!

Cheers,

Daryl Maximo
PHP Programmer - interactivetools.com

By Toledoh - March 24, 2014

Thanks Daryl - but I'm not getting anything displayed for the right sub list...

Cheers,

Tim (toledoh.com.au)

By Daryl - March 25, 2014

Hi Tim,

Can you please try to update the block of codes below and let me know if that fixes it? The changes are colored blue:

// $productsListsRecords will be used for the right sub-list
$productsListsRecords = array();
if (@$_REQUEST['category']){
  $productsListsRecords = array_groupBy($products_listingRecords, 'category', true);
  $productsListsRecords = @$productsListsRecords[$_REQUEST['category']];

Thanks,

Daryl Maximo
PHP Programmer - interactivetools.com

By Toledoh - March 25, 2014

Perfect - thanks Daryl!

Cheers,

Tim (toledoh.com.au)