Created
December 31, 2012 14:55
-
-
Save betaman/4420336 to your computer and use it in GitHub Desktop.
Elefant cms Navigation section
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* these function go to the functions file */ | |
function navigation_has_current_child($children, $pageId){ | |
if(! is_array ($children)){ | |
return false; | |
} else { | |
foreach ($children as $item) { | |
if ($item->attr->id == $pageId || navigation_has_current_child($item->children, $pageId)) { | |
return true; | |
} | |
} | |
return false; | |
} | |
} | |
function navigation_create_item($node, $path, $pageId, $lang) { | |
$classes = array (); | |
/* adds "active" class to parrents of current */ | |
if (navigation_has_current_child($node->children, $pageId)){ | |
array_push($classes, "active"); | |
} | |
if ($node->attr->id == $pageId){ | |
array_push($classes, "current"); | |
} | |
$css = (count ($classes) > 0) ? "class='". implode(" ", $classes) . "'" : ""; | |
printf ('<li %s><a href="/%s/%s">%s</a></li>', $css, $lang, $path, $node->data); | |
} | |
/* this is the actual section.php file */ | |
/* the language part is a little messy I'll clean it up:-) */ | |
$n = new Navigation; | |
$section = $n->node ($data['section']); | |
$lang = $data['lang']; | |
if (is_array ($section->children)) { | |
echo '<ul class="nav">'; | |
foreach ($section->children as $item) { | |
$hrefPath = implode("/",array_slice( $n->path ($item->attr->id), 1)); | |
navigation_create_item($item, $hrefPath, $page->id, $lang); | |
} | |
echo '</ul>'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment