dongmi3203 2014-08-14 17:23
浏览 38
已采纳

如何在Wordpress上修改与php的子页面链接

Hi stackoverflow community,

Well the think is that I have my custom menu already set for all the pages (no problem with that) the options are being getting by:

$links = wp_kses(wp_nav_menu($parameters), $allowed_tags); (I just allow anchor tags and its attributes)

and then:

<nav class="menu-navigation">
 <?php
 echo $links;
 ?>
</nav>

Everything cool so far, however some options on the menu are sections of some pages, like:

Home#contact

Evidently on other pages like the blog page if a don't have the contact section but I click that option it should redirection the user to Home#contact otherwise do not reload the page and just go to the #contact section.

So I want to detect with php which options are child and modify its href depending on the current page. I don't know php enough though so please any ideas and clear walkthrough to get this done?

Thanks in advance.

PD: I would like to avoid use JS if it is possible


Update:

Following the approach of several nav menus

This is my current header-nav code: https://gist.github.com/duranmla/e70cc6073dfb2d79e19f and I make the navigations as suggested. Finally here my dashboard https://www.evernote.com/shard/s243/sh/9896863b-c10b-4e32-bad9-5bbc4341cfd9/d373ab95d0c3c3f5d72f455c03dea7d4/deep/0/Fullscreen-8-15-14,-11-35-AM.png

  • 写回答

1条回答 默认 最新

  • douchongbang6011 2014-08-14 18:07
    关注

    First off, wrapping wp_nav_menu() with wp_kses() seems unnecessary.

    To answer your question, one easy way without much coding would be to create two Menus - one for display on the pages that have a contact section, one for use everywhere else.

    In your theme package, you'll need to be sure there are two menu locations registered.

    register_nav_menus(
      array(
        'home_navigation' => __('Home Navigation'),
        'primary_navigation' => __('Primary Navigation')
      )
    );
    

    See http://codex.wordpress.org/Function_Reference/register_nav_menus

    Then create your menu items in the WordPress admin, under Appearance > Menus. In the first menu, make your link "#contact", and in the second, "/#contact".

    Then in your theme's header.php template, you'll need to indicate which nav menu to use. Here's what it would look like if your home page is the only page which requires the alternate menu:

    if(is_front_page()){
    
      wp_nav_menu(array('theme_location' => 'home_navigation'));
    
    } else {
    
      wp_nav_menu(array('theme_location' => 'primary_navigation'));
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line