代码之家  ›  专栏  ›  技术社区  ›  Hamish Grubijan

如何创建一个不需要由编码人员维护的灵活nav.php

  •  0
  • Hamish Grubijan  · 技术社区  · 15 年前

    我找到了一个我喜欢的链接:用户友好的上下文导航和简单的php包括 http://brainstormsandraves.com/archives/2006/09/27/navigation/

    但是那里的东西是硬编码的。如何使事情变得更容易? 如果有问题请告诉我。

    2 回复  |  直到 15 年前
        1
  •  2
  •   james    15 年前

    这样的解决方案可能很好:

    在新文件中,定义一个数组: $pages=array('home'=>'/index.php'、'news'=>'/news.php');

    然后打印菜单的函数

    function print_menu() {
      foreach($pages as $name=>$url) {
        if ($_SERVER['REQUEST_URI'] == $url) print $name;
        else print '<a href="'.$url.'">'.$name.'</a>';
      }
    }
    
        2
  •  0
  •   Sairam    15 年前

    您可以在客户端使用JavaScript来实现这一点。这样更容易,并且不需要在服务器端修改任何代码。 我要在这里使用jquery-

    function OnLoad(){
         // Assuming the links are in the format http://example.com/section/. 
         // I am stripping out the the 4th (3 in the [] below) column when split with /'s 
         location = document.location.href.split("/")[3];
         $('li.menuitems a[href*='+location+']').each( function() {
              $(this).replaceWith($(this).html());
          });
    });
    

    我真的需要处理我的jquery:(。这只是一个伪代码,我向你保证这是可以实现的 编辑: 正在使jquery工作..

    代码位于 http://pastie.org/1329224 . “关于”的示例页 GoogAppspot

    推荐文章