Wonder if someone could help me out? I know very little about PHP, however I have managed to use GREP to locate the specific bit of code which i need to change:
Bit of PHP code out of Moodle here:
This builds the breadcrumb nav in Moodle,Code://Construct an unordered list from $navlinks //Accessibility: heading hidden from visual browsers by default. $navigation = get_accesshide(get_string('youarehere','access'), 'h2')." <ul>\n"; $lastindex = count($navlinks) - 1; $i = -1; // Used to count the times, so we know when we get to the last item. $first = true; foreach ($navlinks as $navlink) { $i++; $last = ($i == $lastindex); if (!is_array($navlink)) { continue; } if (!empty($navlink['type']) && $navlink['type'] == 'activity' && !$last && $hideactivitylink) { continue; } $navigation .= '<li class="first">'; if (!$first) { $navigation .= get_separator(); } if ((!empty($navlink['link'])) && !$last) { $navigation .= "<a onclick=\"this.target='$CFG->framename'\" href=\"{$navlink['link']}\">"; } $navigation .= "{$navlink['name']}"; if ((!empty($navlink['link'])) && !$last) { $navigation .= "</a>"; } $navigation .= "</li>"; $first = false; } $navigation .= "</ul>"; return(array('newnav' => true, 'navlinks' => $navigation)); }
Basically translates to:
What I want to create is:HTML Code:<ul> <li class="first">Home</li> <li class="first">Course</li> <li class="first">Activity</li> </ul>
Allowing me to create a drop down menu in plain CSS.HTML Code:<ul id="nav"> <li class="navtop">Home</li> <li class="navitem"><a href="http://www.google.com">Course</a></li> <li class="navitem"><a href="http://www.msn.com">Activity</a></li> <li class="navitem"><a href="http://edugeek.net">Web Page</a></li> </ul>
I've managed the first step (The easiest)
Code:$navigation = get_accesshide(get_string('youarehere','access'), 'h2')." <ul>\n";
changed to:
Code:$navigation = get_accesshide(get_string('youarehere','access'), 'h2')." <ul class=nav>\n";

So you want to create a dropdown menu in place of the breadcrumb? The menu won't change much so does it need to be written in PHP?
Can you not just create a seperate file (i.e. menu.php), write the drop down as you need it and then include it in place of where the breadcrumb code is?
I'm not up with PHP too much either so it's just an idea and probably doesn't make sense![]()
It makes sense, but the breadcrumb links are generated dynamically so i cant pre-create the menu links.
Moodle generates them on the fly so i need to get my classes in 'on the fly'
Well, I know nothing about Moodle, but wouldn't this work?
Code://Construct an unordered list from $navlinks //Accessibility: heading hidden from visual browsers by default. //Comment out virtually all of this using the slash and asterisk... /* $navigation = get_accesshide(get_string('youarehere','access'), 'h2')." <ul>\n"; $lastindex = count($navlinks) - 1; $i = -1; // Used to count the times, so we know when we get to the last item. $first = true; foreach ($navlinks as $navlink) { $i++; $last = ($i == $lastindex); if (!is_array($navlink)) { continue; } if (!empty($navlink['type']) && $navlink['type'] == 'activity' && !$last && $hideactivitylink) { continue; } $navigation .= '<li class="first">'; if (!$first) { $navigation .= get_separator(); } if ((!empty($navlink['link'])) && !$last) { $navigation .= "<a onclick=\"this.target='$CFG->framename'\" href=\"{$navlink['link']}\">"; } $navigation .= "{$navlink['name']}"; if ((!empty($navlink['link'])) && !$last) { $navigation .= "</a>"; } $navigation .= "</li>"; $first = false; } */ //The routine above just builds a string called $navigation, which is then fed into Moodle, so why not just //include the HTML you want directly, as in the line below? (Note that the dot before the equals sign has been deleted). $navigation = "<ul id="nav"><li class="navtop">Home</li><li class="navitem"><a href="http://www.google.com">Course</a></li><li class="navitem"><a href="http://www.msn.com">Activity</a></li><li class="navitem"><a href="http://edugeek.net">Web Page</a></li></ul>"; return(array('newnav' => true, 'navlinks' => $navigation)); }
The links i provided were example, the links are dynamic they could be anything depending on which page you land or navigate to.
TO sort the names for your css;
Replace
withCode:$navigation = get_accesshide(get_string('youarehere','access'), 'h2')." <ul>\n"; $lastindex = count($navlinks) - 1; $i = -1; // Used to count the times, so we know when we get to the last item. $first = true; foreach ($navlinks as $navlink) { $i++; $last = ($i == $lastindex); if (!is_array($navlink)) { continue; } if (!empty($navlink['type']) && $navlink['type'] == 'activity' && !$last && $hideactivitylink) { continue; } $navigation .= '<li class="first">'; if (!$first) { $navigation .= get_separator(); } if ((!empty($navlink['link'])) && !$last) { $navigation .= "<a onclick=\"this.target='$CFG->framename'\" href=\"{$navlink['link']}\">"; } $navigation .= "{$navlink['name']}"; if ((!empty($navlink['link'])) && !$last) { $navigation .= "</a>"; } $navigation .= "</li>"; $first = false; } */
As for the links - you would need an array of the urls and the navlinks they apply to and then use a switch to apply them by modifying the url section of that loop. I can't do it for you without knowing what you want though.Code:$navigation = get_accesshide(get_string('youarehere','access'), 'h2')." <ul id=\"nav\" >\n"; $lastindex = count($navlinks) - 1; $i = -1; // Used to count the times, so we know when we get to the last item. $first = true; foreach ($navlinks as $navlink) { $i++; $last = ($i == $lastindex); if (!is_array($navlink)) { continue; } if (!empty($navlink['type']) && $navlink['type'] == 'activity' && !$last && $hideactivitylink) { continue; } if (!$first) { $navigation .= '<li class="navitem">'; $navigation .= get_separator(); } else{ $navigation .= '<li class="navtop">'; } if ((!empty($navlink['link'])) && !$last) { $navigation .= "<a onclick=\"this.target='$CFG->framename'\" href=\"{$navlink['link']}\">"; } $navigation .= "{$navlink['name']}"; if ((!empty($navlink['link'])) && !$last) { $navigation .= "</a>"; } $navigation .= "</li>"; $first = false; } */
Last edited by kesomir; 12th January 2009 at 06:14 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)