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条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮