2015-04-22 101 views
0

Image to describe issue better汽车导航空白链接按钮,跟我的老板正在寻找在导航栏设置一个导航链接,不是页面本身三个不同的父页面

enter image description here

,而是显示器显示下拉下拉列表中有3个单独的父页面(www.website.com/turkey,/ greece,/ italy)。他希望保留新网站的网址结构以避免过度的重定向,这个问题对我来说是个问题,我可以尝试自己解决。

Auto Nav本身使用php来根据网站结构生成导航栏,所以在没有任何php编辑的情况下合并这个导航栏的唯一方法就是使链接成为一个页面(而不仅仅是我的老板想要的空白链接) ,但是它破坏了他想要遵循的url文件结构。

我认为这将不得不在PHP中解决,但我不是很精通它自己,所以真的很感谢一些指导!

道歉,如果有点不清楚,如果需要更清晰,请让我知道!

<?php defined('C5_EXECUTE') or die(_("Access Denied.")); 

$navItems = $controller->getNavItems(); 

/** 
* The $navItems variable is an array of objects, each representing a nav menu item. 
* It is a "flattened" one-dimensional list of all nav items -- it is not hierarchical. 
* However, a nested nav menu can be constructed from this "flat" array by 
* looking at various properties of each item to determine its place in the hierarchy 
* (see below, for example $navItem->level, $navItem->subDepth, $navItem->hasSubmenu, etc.) 
* 
* Items in the array are ordered with the first top-level item first, followed by its sub-items, etc. 
* 
* Each nav item object contains the following information: 
* $navItem->url  : URL to the page 
* $navItem->name  : page title (already escaped for html output) 
* $navItem->target  : link target (e.g. "_self" or "_blank") 
* $navItem->level  : number of levels deep the current menu item is from the top (top-level nav items are 1, their sub-items are 2, etc.) 
* $navItem->subDepth : number of levels deep the current menu item is *compared to the next item in the list* (useful for determining how many <ul>'s to close in a nested list) 
* $navItem->hasSubmenu : true/false -- if this item has one or more sub-items (sometimes useful for CSS styling) 
* $navItem->isFirst : true/false -- if this is the first nav item *in its level* (for example, the first sub-item of a top-level item is TRUE) 
* $navItem->isLast  : true/false -- if this is the last nav item *in its level* (for example, the last sub-item of a top-level item is TRUE) 
* $navItem->isCurrent : true/false -- if this nav item represents the page currently being viewed 
* $navItem->inPath  : true/false -- if this nav item represents a parent page of the page currently being viewed (also true for the page currently being viewed) 
* $navItem->attrClass : Value of the 'nav_item_class' custom page attribute (if it exists and is set) 
* $navItem->isHome  : true/false -- if this nav item represents the home page 
* $navItem->cID  : collection id of the page this nav item represents 
* $navItem->cObj  : collection object of the page this nav item represents (use this if you need to access page properties and attributes that aren't already available in the $navItem object) 
*/ 


/** For extra functionality, you can add the following page attributes to your site (via Dashboard > Pages & Themes > Attributes): 
* 
* 1) Handle: exclude_nav 
* (This is the "Exclude From Nav" attribute that comes pre-installed with concrete5, so you do not need to add it yourself.) 
* Functionality: If a page has this checked, it will not be included in the nav menu (and neither will its children/sub-pages). 
* 
* 2) Handle: exclude_subpages_from_nav 
* Type: Checkbox 
* Functionality: If a page has this checked, all of that pages children (sub-pages) will be excluded from the nav menu (but the page itself will be included). 
* 
* 3) Handle: replace_link_with_first_in_nav 
* Type: Checkbox 
* Functionality: If a page has this checked, clicking on it in the nav menu will go to its first child (sub-page) instead. 
* 
* 4) Handle: nav_item_class 
* Type: Text 
* Functionality: Whatever is entered into this textbox will be outputted as an additional CSS class for that page's nav item (NOTE: you must un-comment the "$ni->attrClass" code block in the CSS section below for this to work). 
*/ 


/*** STEP 1 of 2: Determine all CSS classes (only 2 are enabled by default, but you can un-comment other ones or add your own) ***/ 
foreach ($navItems as $ni) { 
    $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'; 
    } 

    /* 
    if ($ni->isFirst) { 
     //class for the first item in each menu section (first top-level item, and first item of each dropdown sub-menu) 
     $classes[] = 'nav-first'; 
    } 
    */ 

    /* 
    if ($ni->isLast) { 
     //class for the last item in each menu section (last top-level item, and last item of each dropdown sub-menu) 
     $classes[] = 'nav-last'; 
    } 
    */ 


    if ($ni->hasSubmenu) { 
     //class for items that have dropdown sub-menus 
     $classes[] = 'parent'; 
    } 


    /* 
    if (!empty($ni->attrClass)) { 
     //class that can be set by end-user via the 'nav_item_class' custom page attribute 
     $classes[] = $ni->attrClass; 
    } 
    */ 

    /* 
    if ($ni->isHome) { 
     //home page 
     $classes[] = 'nav-home'; 
    } 
    */ 

    /* 
    //unique class for every single menu item 
    $classes[] = 'nav-item-' . $ni->cID; 
    */ 

    //Put all classes together into one space-separated string 
    $ni->classes = implode(" ", $classes); 
} 


//*** Step 2 of 2: Output menu HTML ***/ 
echo '<div id="menu">'; 
echo '<ul class="nav menu">'; //opens the top-level menu 

foreach ($navItems as $ni) { 

    echo '<li class="' . $ni->classes . '">'; //opens a nav item 

    echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '">' . $ni->name . '</a>'; 

    if ($ni->hasSubmenu) { 
     echo '<ul>'; //opens a dropdown sub-menu 
    } else { 
     echo '</li>'; //closes a nav item 
     echo str_repeat('</ul></li>', $ni->subDepth); //closes dropdown sub-menu(s) and their top-level nav item(s) 
    } 
} 

echo '</ul>'; //closes the top-level menu 
echo '</div>'; //closes the top-level menu-container 
+1

我不知道我明白问题的确切位置?也许你应该编辑这个问题。这是什么意思“*,而是在下拉菜单中显示3个单独的父页面(www.website.com/turkey,/ greece,/ italy)*”? –

+0

感谢您回复我。对不起,我添加了一张图片,以更好地解释页面的顶部。下拉菜单基于站点地图进行填充。该网站地图目前是首页>目的地>土耳其.etc,它需要更改为首页> Tukey .etc,同时将目的地保留在自动导航栏中 – Nexus1234

+0

如果它不是必需的,并且可以通过其他方式访问这些项目,那么我可能只是使用JavaScript将这些链接添加到导航客户端。 – CBroe

回答

0

我建议只需添加一个特殊的配置,以ammend汽车导航菜单的类似链接如下:

$navItems = $controller->getNavItems(); 

$special_config = array(
    "www.website.com/turkey" /* url */=> array("level" => 2), 
    "www.website.com/greece" /* url */=> array("level" => 2) 
    // .. rest special config here 
); 

foreach ($navItems as &$navItem) 
{ 
    if (isset($special_config[$navItem->url])) 
    { 
      foreach ($special_config[$navItem->url] as $k=>$v) 
      { 
       // adjust navItem params as needed here by key=>value 
       $navItem->{$k} = $v; 
      } 
    } 
} 

// rest code follows 
// ... 

你甚至可以使一个功能ammend_nav_menu这样的:

function ammend_nav_menu($special_config, &$navItems) 
{ 
    foreach ($navItems as &$navItem) 
    { 
     if (isset($special_config[$navItem->url])) 
     { 
       foreach ($special_config[$navItem->url] as $k=>$v) 
       { 
        // adjust navItem params as needed here by key=>value 
        $navItem->{$k} = $v; 
       } 
     } 
    } 
} 

以及原样使用:

$navItems = $controller->getNavItems(); 
ammend_nav_menu(array(
    "www.website.com/turkey" /* url */=> array("level" => 2), 
    "www.website.com/greece" /* url */=> array("level" => 2) 
    // .. rest special config here 
), $navItems); 

修正菜单的特殊配置甚至可以在一个单独的php文件中,并根据需要加载/更新

+0

感谢您的建议和代码,非常感谢,虽然我必须承认我不确定我会如何应用这个关于导航的PHP代码。我尝试了两种方法,我认为它应该去,我没有看到一个变化,但我很可能监督 – Nexus1234

+0

@ Nexus1234,该解决方案使用特殊配置的某些链接将它们放在另一个级别(如目的地)而通过新的网站地图,他们应该在顶层(这是你的问题)。在示例解决方案中,我使用'level'成为** 2 **,但由于我不知道链接的所有参数以及它们如何相关,所以您可能会使用其他配置,如果需要 –

+0

@ Nexus1234,您甚至可以添加一个虚拟菜单(“目的地”)和额外的数据在修正后的'navItems'中,所以在你的主循环中你可以为这些链接构建所需的菜单层次结构(即,e是在虚拟菜单“目的地”下) –