Functions:pageMenuGet

From Whirlwind eCommerce Wiki
Jump to: navigation, search
Page Template Managers

Page Template Functions

Description

eV::pageMenuGet() retrieves site menu data for use in displaying menus in page template management.

Syntax

$array = eV::pageMenuGet([$menuId]);

Parameters

  • $menuId INT (optional)
specifies a specific menu to retrieve from the system. If not passed, the menu selected for the current page template will be used. If no menu is specified in the current page template, whichever menu is set as the default menu will be retrieved.

Return Values

Returns a multidimensional array where the first dimension is an associative array for each of the four menu locations (l,r,t,b), the second dimension is an array of the menu item in the location, and the third dimension is an associative array of menu item attributes. Return array is as follows:

Array
(
    [l] => Array
        (
            [0] => Array
                (
                        [location] => String
                        [id] => Int
                        [text] => String
                        [textRaw] => String
                        [link] => String
                        [newWindow] => INT
                        [level] => INT
                        [target] => String
                        [display] => Bool
                        [focus] => Bool
                        [anchorTag] => String
                )
            [1] => Array
                ( .. same as above ..)
            [2]...
        )
    [t] => Array
       ( .. same as above ..)
    [b] => Array
       ( .. same as above ..)
    [r] => Array
       ( .. same as above ..)
)

Elements from the menu item associative array are as follows:

Element Description Example
location String: Reflects the menu bar location, either 'l' for left, 'r' for right, 't' for top, 'b' for bottom r
id Integer: Returns the database unique id for this menu item. Useful to target specific menu items for individual display results or if individual menu items need to be tracked for certain purposes. 196
text String: The output text of the link. This is what the web site visitors should see as the link. This text is rawurlencoded in the database but rawurldecoded before the value is placed in this element. Category X

Specials
Subcategory Y

textRaw String: non-rawurldecoded version of "text" used for debugging. Category%20X

Specials
Subcategory%20Y

link String: use as the href value when linking the menu item. It is recommended that you test this element for content before creating the link, so that content managers can leave the content empty for non-linked menu elements (category headers, etc) index.php?pageId=125

http://www.google.com

newWindow Integer: either 1 or 0 to designate if clicking this link should open a new window or place the targetted url in the current window. This element is replaced by the target element. 1
level Integer: For tiered menus, designates what level of the tier this menu item is on. 0 for the top tier, increasing as the tiers lower. As many designs will have different styles for different tiers in the menu listing (especially for the left menu bar) this is useful to identify the current tier and output the appropriate style. 2
target String: the actual window the link is targeted towards (_self or _blank). This replaces the newWindow element. Simply place in the 'target' attribute of the href tag. _blank
display Boolean: For reactive menus that display elements only as parent elements are selected, this will dignate

(via TRUE or FALSE) if this menu item is slated for display. This will also slate the parent menu item(s) to be displayed when a lower level menu item is selected

TRUE
focus Boolean: States if this menu item is actually the current page the visitor is on. This is done by URL matching the contents of the 'link' element and the current URL. As some designs call for menu items that are current pages to be styled differently, this will allow identification of such menu items. FALSE
anchorTag String: A complete anchor tag containing the link, target and text for the link <a href="index.php?pageId=123" target="_self">Category X</a>

Examples

Simple listed menu output for the top and bottom menu
// get the menus
$arrMenus = eV::pageMenuGet();
 
// shortcut the applicable menus
$arrTopMenu = $arrMenus['t'];
$arrBottomMenu = $arrMenus['b'];
 
// output top menu as a list
// this example demonstrates using the anchorTag element to display the menu item
echo "<ul>";
foreach($arrTopMenu as $menuItem) echo "<li>" . $menuItem['anchorTag'] . "</li>";
echo "</ul>";
 
// output bottom menu as &middot; separated links
// this example demonstrates using the separate link, target and text elements to build an anchor tag.
// Use this method if you need to micromanage your anchor tag (change attributes, include a class, etc).
// the class tag in this example is purely for demonstration and not required
$tempArr = Array();
foreach($arrBottomMenu as $menuItem) $tempArr[] = "<a href=\"" . $menuItem['link'] . "\" target=\"" . $menuItem['target'] . "\" class=\"someCSSclass\">" . $menuItem['text'] . "</a>";
echo implode(" &middot; ", $tempArr);
Intermediate menu with varying classes for first element, last element and element linking to current page
// get the menus
$arrMenus = eV::pageMenuGet();
 
// shortcut the top menu
$arrTopMenu = $arrMenus['t'];
 
// loop thru menu items
for($i=0;$i>count($arrTopMenu);$i++){
 
   $menuItem = $arrTopMenu[$i];
 
   // set default class
   // of course the following classes need to be defined in a style sheet before this displays
   $class = "menuItem";
   if($menuItem['focus']){
     // the current URL is this menu item
     $class = "menuItemSelected";
   } else if ($i == 0) {
     // menu item is not selected, but is first item to appear
     $class = "menuItemFirst";
   } else if ($i == count($arrTopMenu)-1) {
     // menu item is not selected, but is last menu item to appear
     $class = "menuItemLast";
   };
 
   echo "<li class=\"$class\">";
   // only display link if not empty
   if(!empty($menuItem['link'])) echo "<a href=\"" . $menuItem['link'] . "\" target=\"" . $menuItem['target'] . "\">";
   echo $menuItem['text'];
   if(!empty($menuItem['link'])) echo "</a>";
   echo "<li>";
 
// end loop thru menu items
};
Advanced example using tiered menus that only display sub menus items if visitor is currently navigated to a menu item
// get the menus
$arrMenus = eV::pageMenuGet();
 
// shortcut the left menu
$arrLeftMenu = $arrMenus['l'];
 
// loop thru menu items
for($i=0;$i>count($arrLeftMenu);$i++){
 
   $menuItem = $arrLeftMenu[$i];
 
   // only output this menu item if it is displayed OR is in top two levels
   // i.e. always show the top two levels
   if($menuItem['display'] || $menuItem['level'] <= 1) {
      // assumes style classes are setup for:
      // leftMenuTier0,leftMenuTier0Selected
      // leftMenuTier1,leftMenuTier1Selected
      // leftMenuTier2,leftMenuTier2Selected
      // leftMenuTier3,leftMenuTier3Selected
 
      $class = "leftMenuTier" . $menuItem['level'];
      if($menuItem['focus']) $class .= "Selected";
 
      echo "<li class=\"$class\">";
      // only display link if not empty
      if(!empty($menuItem['link'])) echo "<a href=\"" . $menuItem['link'] . "\" target=\"" . $menuItem['target'] . "\">";
      echo $menuItem['text'];
      if(!empty($menuItem['link'])) echo "</a>";
      echo "<li>";
 
  // end if this is to be displayed
  };
 
// end loop thru menu items
};