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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了