dongzhi1949 2012-04-20 14:19 采纳率: 100%
浏览 12
已采纳

如何使用PHP从活动导航页面中删除锚点?

I am sure this is a fairly simple question to answer, but I am new to PHP, so I was hoping someone could help me solve this problem.

I have a dynamic navigation menu that works really well, but I want to remove the link from the current page in the menu.

Here is my code:

  <div id="navigation_menu">
  <?
  foreach($pagedata->menu as $menuitem){
      $class = ($menuitem->uri == $requesteduri) ? 'navigation selection' : 'navigation page_select';

      ?>
      <div id="<?=$menuitem->uri?>" class="<?=$class?>">
        <img class="nav_icon" src="<?=PROTOCOL?>//<?=DOMAIN?>/img/<?=$menuitem->uri?>.png">
        <h1><a href="<?=PROTOCOL?>//<?=DOMAIN?>/<?=$menuitem->uri?>"><?=$menuitem->title?></a></h1>
        <h2><?=$menuitem->description?></h2>
        <img class="go" src="<?=PROTOCOL?>//<?=DOMAIN?>/img/go.png">
      </div>
      <?      
  }
  ?>
  </div>

Any help would be greatly appreciated. Thanks!

UPDATED CODE: (this is what works for me now)

<div id="navigation_menu">
    <?
  foreach($pagedata->menu as $menuitem){
      $class = ($menuitem->uri == $requesteduri) ? 'navigation selection' : 'navigation page_select';
      ?>
      <div id="<?=$menuitem->uri?>" class="<?=$class?>">
        <img class="nav_icon" src="<?=PROTOCOL?>//<?=DOMAIN?>/img/<?=$menuitem->uri?>.png">
        <h1>
                <?php if ($menuitem->uri == $requesteduri):?>
            <?=$menuitem->title;?>
                <?php else: ?>
            <a href="<?=PROTOCOL?>//<?=DOMAIN?>/<?=$menuitem->uri?>"><?=$menuitem->title?></a>
                <?php endif;?>
                </h1>
        <h2><?=$menuitem->description?></h2>
        <img class="go" src="<?=PROTOCOL?>//<?=DOMAIN?>/img/go.png">
      </div>

      <?      
  }

  ?>
  </div>

展开全部

  • 写回答

2条回答 默认 最新

  • douhao7889 2012-04-20 14:27
    关注

    I don't know what your loop is outputting, but you want to match your page name with the menuitem->uri. So you'd get your page name like.. (Put this outside the loop)

    <?php echo base_name($_SERVER['REQUEST_URI']); ?>
    

    find out what your loop is outputting (Put this in the loop):

    <?php echo $menuitem->uri; ?>
    

    Then you'd create an if statement to compare the current menuitem in the loop and the page request, this is just an example:

    <h1>
    <?php if (base_name($_SERVER['REQUEST_URI']) == $menuitem->uri):?>
       <a href="<?=PROTOCOL?>//<?=DOMAIN?>/<?=$menuitem->uri?>"><?=$menuitem->title?></a>
    <?php else: ?>
       <?=$menuitem->title;?>
    <?php endif;?>
    </h1>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 为什么投影机用酷喵播放电影放一段时间就播放不下去了?提示发生未知故障,有什么解决办法吗?
  • ¥15 来个会搭建付费网站的有偿
  • ¥100 有能够实现人机模式的c/c++代码,有图片背景等,能够直接进行游戏
  • ¥20 校园网认证openwrt插件
  • ¥15 以AT89C51单片机芯片为核心来制作一个简易计算器,外部由4*4矩阵键盘和一个LCD1602字符型液晶显示屏构成,内部由一块AT89C51单片机构成,通过软件编程可实现简单加减乘除。
  • ¥15 求GCMS辅导数据分析
  • ¥30 SD中的一段Unet下采样代码其中的resnet是谁跟谁进行残差连接
  • ¥15 Unet采样阶段的res_samples问题
  • ¥15 R语言regionNames()和demomap()无法选中中文地区的问题
  • ¥15 Open GL ES 的使用
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部