Using BrotherCake CSS Menus
Posted: Sun Feb 06, 2005 1:11 am
Hi
Sorry but I'm not a fan of the PHPLayers Menu - tables, bad CSS etc.
I love Brother Cake CSS menus (www.udm4.com) - they are very simple to implement and offer almost infinite customisation.
I have created a quick User Plugin to allow me to use Brother Cake Menus on my site instead of PHPLayers.
Thanks to Julien Lancien for his code in BulletMenu which most of this was based on.
1. Create a new User Plugin called "brothermenu"
2. Insert the following code.
global $gCms;
global $db;
# getting menu parameters
$showadmin = isset($params["showadmin"]) ? $params["showadmin"] : 1 ;
$allcontent = ContentManager::GetAllContent();
# defining variables
$menu = "";
$last_level = 0;
$count = 0;
$in_hr = 0;
if (count($allcontent))
{
$menu .= "\n";
foreach ($allcontent as $onecontent)
{
#Handy little trick to figure out how deep in the tree we are
#Remember, content comes to use in order of how it should be displayed in the tree already
$depth = count(split('\.', $onecontent->Hierarchy()));
#If hierarchy starts with the start_element (if it's set), then continue on
if (isset($params['start_element']))
{
if (!(strpos($onecontent->Hierarchy(), $params['start_element']) !== FALSE && strpos($onecontent->Hierarchy(), $params['start_element']) == 0))
{
continue;
}
}
#Now check to make sure we're not too many levels deep if number_of_levels is set
if (isset($params['number_of_levels']))
{
$number_of_levels = $params['number_of_levels'] - 1;
$base_level = 1;
#Is start_element set? If so, reset the base_level to it's level
if (isset($params['start_element']))
{
$base_level = count(split('\.', $params['start_element']));
}
#If this element's level is more than base_level + number_of_levels, then scratch it
if ($base_level + $number_of_levels Active() || !$onecontent->ShowInMenu())
{
continue;
}
if ($onecontent->Type() == 'sectionheader')
{
if ($in_hr == 1)
{
$menu .= "\n";
$in_hr = 0;
}
$menu .= "".$onecontent->MenuText()."\n";
if ($count > 0 && $in_hr == 0)
{
$menu .= "\n";
$in_hr = 1;
}
}
else
{
if ($depth \n\n";
if ($depth > 0)
{
$menu .= "\n";
}
}
if ($depth > $last_level) {
if ($last_level == 0)
{
for ($i = $depth; $i > $last_level; $i--) $menu .= "\n\n";
}
else
{
for ($i = $depth; $i > $last_level; $i--) $menu .= "\n\n";
}
}
if ($depth == $last_level) {
$menu .= "\n";
}
if ($onecontent->Type() == 'separator')
{
$menu .= "";
}
else
{
$menu .= "GetURL()."\"";
if (isset($gCms->variables['page_id']) && $onecontent->Id() == $gCms->variables['page_id'])
{
$menu .= " class=\"currentpage\"";
}
$menu .= ">".$onecontent->MenuText()."";
}
$in_hr = 1;
$last_level = $depth;
}
$count++;
}
for ($i = 0; $i ";
if ($showadmin == 1)
{
$menu .= "Admin\n";
}
$menu .= "\n";
}
echo $menu;
3. As per the brothercake instal instrcutions you'll need to add the following to your head section:
and, depending on the style you want
4. Finally in your body section add:
You can now call the menus using:
{brothermenu showadmin="0"}
In fact, it uses the same as bulletmenu
showadmin - 1/0, whether you want to show or not the admin link.
start_element - the hierarchy of your element (ie : 1.2 or 3.5.1 for example). This parameter sets the root of the menu.
number_of_levels - an integer, the number of levels you want to show in your menu.
Sorry but I'm not a fan of the PHPLayers Menu - tables, bad CSS etc.
I love Brother Cake CSS menus (www.udm4.com) - they are very simple to implement and offer almost infinite customisation.
I have created a quick User Plugin to allow me to use Brother Cake Menus on my site instead of PHPLayers.
Thanks to Julien Lancien for his code in BulletMenu which most of this was based on.
1. Create a new User Plugin called "brothermenu"
2. Insert the following code.
global $gCms;
global $db;
# getting menu parameters
$showadmin = isset($params["showadmin"]) ? $params["showadmin"] : 1 ;
$allcontent = ContentManager::GetAllContent();
# defining variables
$menu = "";
$last_level = 0;
$count = 0;
$in_hr = 0;
if (count($allcontent))
{
$menu .= "\n";
foreach ($allcontent as $onecontent)
{
#Handy little trick to figure out how deep in the tree we are
#Remember, content comes to use in order of how it should be displayed in the tree already
$depth = count(split('\.', $onecontent->Hierarchy()));
#If hierarchy starts with the start_element (if it's set), then continue on
if (isset($params['start_element']))
{
if (!(strpos($onecontent->Hierarchy(), $params['start_element']) !== FALSE && strpos($onecontent->Hierarchy(), $params['start_element']) == 0))
{
continue;
}
}
#Now check to make sure we're not too many levels deep if number_of_levels is set
if (isset($params['number_of_levels']))
{
$number_of_levels = $params['number_of_levels'] - 1;
$base_level = 1;
#Is start_element set? If so, reset the base_level to it's level
if (isset($params['start_element']))
{
$base_level = count(split('\.', $params['start_element']));
}
#If this element's level is more than base_level + number_of_levels, then scratch it
if ($base_level + $number_of_levels Active() || !$onecontent->ShowInMenu())
{
continue;
}
if ($onecontent->Type() == 'sectionheader')
{
if ($in_hr == 1)
{
$menu .= "\n";
$in_hr = 0;
}
$menu .= "".$onecontent->MenuText()."\n";
if ($count > 0 && $in_hr == 0)
{
$menu .= "\n";
$in_hr = 1;
}
}
else
{
if ($depth \n\n";
if ($depth > 0)
{
$menu .= "\n";
}
}
if ($depth > $last_level) {
if ($last_level == 0)
{
for ($i = $depth; $i > $last_level; $i--) $menu .= "\n\n";
}
else
{
for ($i = $depth; $i > $last_level; $i--) $menu .= "\n\n";
}
}
if ($depth == $last_level) {
$menu .= "\n";
}
if ($onecontent->Type() == 'separator')
{
$menu .= "";
}
else
{
$menu .= "GetURL()."\"";
if (isset($gCms->variables['page_id']) && $onecontent->Id() == $gCms->variables['page_id'])
{
$menu .= " class=\"currentpage\"";
}
$menu .= ">".$onecontent->MenuText()."";
}
$in_hr = 1;
$last_level = $depth;
}
$count++;
}
for ($i = 0; $i ";
if ($showadmin == 1)
{
$menu .= "Admin\n";
}
$menu .= "\n";
}
echo $menu;
3. As per the brothercake instal instrcutions you'll need to add the following to your head section:
and, depending on the style you want
4. Finally in your body section add:
You can now call the menus using:
{brothermenu showadmin="0"}
In fact, it uses the same as bulletmenu
showadmin - 1/0, whether you want to show or not the admin link.
start_element - the hierarchy of your element (ie : 1.2 or 3.5.1 for example). This parameter sets the root of the menu.
number_of_levels - an integer, the number of levels you want to show in your menu.