if statement inside the getCategories

3 posts by 2 authors in: Forums > CMS Builder
Last Post: December 30, 2019   (RSS)

By daniel - December 30, 2019

Hi Zicky,

It's certainly possible to modify an options array based on an if condition - it just requires breaking things down into a few steps. First, you'll want to create the options array as a variable, then use the if condition to modify that array variable, and finally pass that array variable to the functions. That would look something like this:

$categoryOptions = array(
  'tableName'   => 'about',
  'categoryFormat' => 'showall',
);

if ($settingsRecord['menu_1_tier'] =='1') {
  $categoryOptions['ulAttributes'] = 'class="vertical menu"'; 
}

list($aboutRecords, $selectedCategory) = getCategories($categoryOptions);

The above hasn't been tested so you may need to make some adjustments to get it to work in your code, but hopefully, this gets you pointed in the right direction. Let me know if you have any questions!

Thanks,

Daniel
PHP Programmer
interactivetools.com

By Zicky - December 30, 2019

Thanks for the help Daniel, I got this working now. : )