0

我试图在 Concrete5 中为下拉菜单结合两件事,但似乎无法使其正常工作,想知道是否有人可以帮助我。

我有这个菜单的代码

    <?
    defined('C5_EXECUTE') or die(_("Access Denied."));
    $aBlocks = $controller->generateNav();
    global $c;

    if ($c->isEditMode()) {
            echo("<div class=\"menu\" style=\"position:inherit!important;\"><ul>");
    }
    else {
            echo("<div class=\"menu\"><ul>");
    }

    $nh = Loader::helper('navigation');

    foreach($aBlocks as $ni) {
            $_c = $ni->getCollectionObject();
            if (!$_c->getCollectionAttributeValue('exclude_nav')) {

                    $thisLevel = $ni->getLevel();

                    if ($thisLevel > $lastLevel) {
                            echo("<!--[if IE 7]><!--></a><!--<![endif]-->\n<!--[if lte IE 6]><table><tr><td><![endif]-->\n<ul>\n");
                    } else if ($thisLevel < $lastLevel) {
                            for ($j = $thisLevel; $j < $lastLevel; $j++) {
                                    echo("</a></li>\n</ul>\n<!--[if lte IE 6]></td></tr></table></a><![endif]--></li>\n");
                            }
                    }

                    if ($thisLevel == $lastLevel && $i >0) {
                       echo "</a></li>\n";
                    }

                    $pageLink = false;

                    if ($_c->getCollectionAttributeValue('replace_link_with_first_in_nav')) {
                            $subPage = $_c->getFirstChild();
                            if ($subPage instanceof Page) {
                                    $pageLink = $nh->getLinkToCollection($subPage);
                            }

                    }

                    if (!$pageLink) {
                            $pageLink = $ni->getURL();
                    }

                      if ($_c->getCollectionAttributeValue('placeholder')) {
                             $pageLink="javascript:void(0)";
                     }


                    echo '<li><a href="'.$pageLink.'">' . $ni->getName();

                    $lastLevel = $thisLevel;
                    $i++;
            }
    }

    $thisLevel = 0;
    for ($i = $thisLevel; $i <= $lastLevel; $i++) {
            echo("</a></li></ul>");
    }
    echo '</div>';
    ?>        

但是没有任何运气来设计导航选择的样式,所以我想在 foreach 开头的行下添加:

    $classes = array();

    if ($ni->isCurrent) {
            //class for the page currently being viewed
            $classes[] = 'nav-selected';
    }

    if ($ni->inPath) {
            //class for parent items of the page currently being viewed
            $classes[] = 'nav-path-selected';
    }

从另一个菜单中,可以设置导航选择的样式,但这没有什么区别。有谁看到我做错了什么,或者有人可以给我一个提示如何完成这项工作?我非常感谢您的帮助。谢谢!

4

1 回答 1

0

It appears as though you've taken code from two different places and pasted them together (which rarely works). I think your first code sample is from an old template, and the second code sample is from the newer one.

Your best bet here is to start from scratch with the newer, cleaner autonav template: https://raw.github.com/concrete5/concrete5/master/web/concrete/blocks/autonav/view.php

It shouldn't be too difficult to modify that to do what you want. If you run into trouble with that, try posting as a new question, either here or in the concrete5 forums ( http://concrete5.org/community/forums ).

于 2013-02-26T16:12:40.503 回答