getMenuItems() public static method

Common usage: Get items of a first menu level (to display on top of the site), e.g., $result = \Ip\Menu\Helper::getMenuItems('menu1', 1, 1); Get 7 levels of children of selected page on top menu (to display on a side): $result = \Ip\Menu\Helper::getMenuItems('menu1', 2, 7); Pass the result to ipSlot('menu', array('items' => $result)); Please note, that items of a child level can only be returned if a selected page is in a breadcrumb parent page. In opposite case, the function returns an empty array.
public static getMenuItems ( string $menuName, integer $depthFrom = 1, integer $depthTo = 1000, string $orderBy = null ) : array
$menuName string eg menu1
$depthFrom integer
$depthTo integer
$orderBy string can be set to 'title' to change ordering
return array
Beispiel #1
0
 /**
  * @desc Generate menu with custom ul ID and class
  * @author Allan Laal <*****@*****.**>
  * @param array $params
  * @return string
  */
 public static function menu_80($params)
 {
     $data = array('items' => null, 'depth' => 1, 'active' => 'active', 'crumb' => 'crumb', 'disabled' => 'disabled', 'parent' => 'parent', 'children' => 'children', 'view' => 'Ip/Internal/Config/view/menu.php');
     if (is_string($params)) {
         $params = array('items' => $params);
     }
     if (!empty($params[0]) && is_object($params[0]) && $params[0] instanceof \Ip\Menu\Item) {
         $params = array('items' => $params);
     }
     $data = array_merge($data, $params);
     // pass params to View along with other data
     if (isset($params['items']) && is_string($params['items'])) {
         $data['items'] = \Ip\Menu\Helper::getMenuItems($params['items']);
     }
     if (empty($data['attributes']) || !is_array($data['attributes'])) {
         $data['attributes'] = array();
     }
     //generate attributes str
     if (empty($data['attributes']['class'])) {
         $data['attributes']['class'] = '';
     }
     $data['attributes']['class'] = 'level' . $data['depth'] . ' ' . $data['attributes']['class'];
     $data['attributesStr'] = join(' ', array_map(function ($sKey) use($data) {
         if (is_bool($data['attributes'][$sKey])) {
             return $data['attributes'][$sKey] ? $sKey : '';
         }
         return $sKey . '="' . $data['attributes'][$sKey] . '"';
     }, array_keys($data['attributes'])));
     $view = ipView($data['view'], $data);
     return $view->render();
 }
Beispiel #2
0
                </div>
            </div>
            <div class="row">
                <div class="small-12 column mobileMenuButton"><?php 
echo __('Menu', 'Glara');
?>
</div>
                <?php 
if (count(ipContent()->getLanguages()) > 1) {
    ?>
                <div class="small-12 column">
                    <nav class="languages">
                        <?php 
    echo ipSlot('languages');
    ?>
                    </nav>
                </div>
                <?php 
}
?>
                <div class="small-12 column">
                    <nav class="main_nav">
                        <?php 
$items = \Ip\Menu\Helper::getMenuItems('menu1', 1, 2);
echo ipSlot('menu', array('items' => $items, 'view' => ipThemeFile('view/menu.php')));
?>
                    </nav>
                </div>
            </div>
        </header>
    <div class="row content">