dongzhi1949 2012-04-20 22: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 22: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条)

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致