I am using OpenPublish 2.2 and I would added some child links under the Home link in the primary menu system. What I found is that the Home link is not marked active by the system when I am on the front page, so the "on" class isn't added to that link, so the child links aren't displayed unless you hover over the link. I would like them to show by default. I know that the main menu system is controlled by openpublish-menu.tpl.php in sites/all/modules/openpublish_core/openpublish_menu. This is the code that appears there:
<ul class="links primary-links clearfix op-primary-links">
<?php if (is_array($expanded_primary_links)): ?>
<?php foreach ($expanded_primary_links as $top_item): ?>
<?php
$html_title = t($top_item->title);
$title_link = l($html_title, $top_item->href, array('html' => TRUE,
'attributes' => array('class' => "first-level")));
?>
<li class="first-level <?php print ($top_item->active ? $top_item->active : "off"); ?>">
<?php print $title_link; ?>
<?php if (is_array($top_item->sublinks) && sizeof($top_item->sublinks) > 0): ?>
<ul class="second-level">
<?php foreach ($top_item->sublinks as $submenu): ?>
<li><?php print l(t($submenu->html_title), $submenu->href, array('html' => TRUE)); ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>How could I modify this so that the home link is marked active, and the "on" class is applied to it when I visit the front page of the site? Thanks in advance for your help!
James
Comments
Ok I got the desired
Ok I got the desired functionality working, but I had to hack the openpublish_menu.module file, located at sites/all/modules/openpublish_core/openpublish_menu, to do it, so it is not an ideal solution. I modified the openpublish_menu_set_active_parent() function from this:
/*** Iterates over top-level items and sets the active flag
*/
function openpublish_menu_set_active_parent($menu_map, $active_path) {
foreach ($menu_map as $id => $menu) {
if ($menu->href == $active_path) {
$menu_map[$id]->active = "on";
}
}
return $menu_map;
}
To this:
/*** Iterates over top-level items and sets the active flag
*/
function openpublish_menu_set_active_parent($menu_map, $active_path) {
foreach ($menu_map as $id => $menu) {
if ($menu->href == $active_path) {
$menu_map[$id]->active = "on";
}
elseif ($menu->title == "Home") {
$menu_map[$id]->active = "on";
}
}
return $menu_map;
}
As you can see I had to tie the else function to the menu title, which is not ideal either since this will break if I change the title of the link. If anyone sees a better way to do this, please let me know. Thanks!