I made a Category Menu and some root levels have children and some don't.
The html has to come out like below.
<ul class="dropdown menu" data-dropdown-menu>
<li>
<a href="#">Item 1</a>
<ul class="menu">
<li><a href="#">Item 1A</a></li>
<!-- ... -->
</ul>
</li>
<li><a href="#">Item 2</a></li>
<li><a href="#">Item 3</a></li>
<li><a href="#">Item 4</a></li>
</ul>
Notice the UL goes after the <a>, and not inside of it. So any root level that has children have the anchor and the whole UL inside of the li. I don't seem to have control of where internal ul tags go so I'm lost My attempts are basically moving around the default CMSB category code. I figured the li had to go in each if statement? What I'm putting here is basically one of 10 attempts but is clearly wrong. I'm lost.
// load records from 'menu_items'
list($menu_itemsRecords, $menu_itemsMetaData) = getRecords(array(
'tableName' => 'menu_items',
'loadUploads' => true,
'allowSearch' => false,
));
// load records from 'menu_cats'
list($menu_catsRecords, $selectedMenu_cats) = getCategories(array(
'tableName' => 'menu_cats', //
'categoryFormat' => 'showall', // showall, onelevel, twolevel, breadcrumb
'defaultCategory' => '', // Enter 'first', a category number, or leave blank '' for none
// advanced options (you can safely ignore these)
'rootCategoryNum' => '0', // Only categories _below_ this one will be shown (defaults to blank or 0 for all)
'ulAttributes' => 'class="menu"', // add html attributes to <ul> tags, eg: 'class="menuUL"' would output <ul class="menuUL">
'selectedCategoryNum' => '', // this record number is returned as the "selected category", defaults to getLastNumberInUrl()
'ulAttributesCallback' => '', // ADVANCED: custom function to return ul attributes, eg: 'myUlAttr' and function myUlAttr($category) { return "id='ul_uniqueId_{$category['num']}'"; }
'liAttributesCallback' => '', // ADVANCED: custom function to return li attributes, eg: 'myLiAttr' and function myLiAttr($category) { return "id='li_uniqueId_{$category['num']}'"; }
'loadCreatedBy' => false, // loads createdBy.* fields for user who created category record (false is faster)
'loadUploads' => true, // loads upload fields, eg: $category['photos'] gets defined with array of uploads (false is faster)
'ignoreHidden' => false, // false = hide records with 'hidden' flag set, true = ignore status of hidden flag when loading records
'debugSql' => false, // display the MySQL query being used to load records (for debugging)
));
<ul class="dropdown menu" data-dropdown-menu>
<?php foreach ($menu_catsRecords as $categoryRecord): ?>
<?php if($categoryRecord['_hasChild'] && $categoryRecord['depth'] == '0'): ?>
<?php echo $categoryRecord['_listItemStart'] ?>
<a href="#"><?php echo $categoryRecord['name'] ?></a>
<?php else: ?>
<?php echo $categoryRecord['_listItemStart'] ?>
<a href="<?php echo $categoryRecord['name'] ?>"</a>
<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endif ?>
<?php endforeach; ?>
</ul>