Home > 7 > Make the Main Menu have dynamic links based on url

Make the Main Menu have dynamic links based on url

May 31Hits:1
Advertisement

My main menu has links to common things: HOME | PHOTOS | VIDEOS ... etc. Home points to /, PHOTOS points to /photo-galleries and VIDEOS points to /videos

The client has added a new feature request and I'm trying to figure out how to handle this. The site has a couple of general topics, let's say baseball, football and soccer.

When I browse to the main home page /, then the menu should point to /photo-galleries and /videos.

However, when I browse to the "baseball filtered" home page /baseball then I'd like the photo galleries menu link to point to /photo-galleries/baseball and the videos link to point to /videos/baseball.

This "filtering" should follow them through out the site, so once they are on /videos/baseball then all of the menu links should continue to have the baseball element on them.

I'm unsure how to approach this problem and I feel like there should be an elegant way to handle this and I'm not the first person to have this problem.

I understand how to setup my various Views on the different pages so they have contextual filters and only show the content items with the baseball tag, but my big question is about how to handle re-writing all of the URLs of the menus and the content URLs.

Help? :)

Answers

3 (updated) options (or a combination thereof) for you to consider:

  1. The drupal module Menu Token provides the ability to put variables in your menu options -- and used in conjunction with your existing context filtered views, may work for you if it allows you to construct the menu options you need based on other tokens that it makes available to you.
  2. The other option is to consider an alternative approach (sorry! :) ). This would be faceted filtering. Follow the tutorials here: http://webwash.net/tutorials/intro-search-api-part-1-how-create-search-pages This is possible on even the most modest of hosting as it does not require Solr (but it can use it if you need that functionality later).
  3. (added in update) Drupal module Menu Trail By Path

I think option 1 (perhaps in conjunction with option 3) might be the closest to what you are looking for though.

Hope this will help you,

In Drupal 7, for your requirement you can use ThemeName_links__system_main_menu function in your template.php file. This function works only for Main menu.

function ThemeName_links__system_main_menu($variables) {
  $links = $variables['links'];
  $html = "<div><ul>";
  foreach ($links as $link) {
    if(baseball filtered) {
      if(home menu) {
        $link['href'] = 'baseball';
      }
      if(photo menu) {
        $link['href'] = 'photo-galleries/baseball';
      }
      if(video menu) {
        $link['href'] = 'videos/baseball';
      }
    }
    elseif(filter is football) {
      if(home menu) {
        $link['href'] = 'football';
      }
      if(photo menu) {
        $link['href'] = 'photo-galleries/football';
      }
      if(video menu) {
        $link['href'] = 'videos/football';
      }
    }
    elseif(filter is soccer) {
      if(home menu) {
        $link['href'] = 'soccer';
      }
      if(photo menu) {
        $link['href'] = 'photo-galleries/soccer';
      }
      if(video menu) {
        $link['href'] = 'videos/soccer';
      }
    }
    else {//for normal
      if(home menu) {
        $link['href'] = 'node';
      }
      if(photo menu) {
        $link['href'] = 'photo-galleries';
      }
      if(video menu) {
        $link['href'] = 'videos';
      }
    }
    $html .= "<li>" . l($link['title'], $link['href'], $link) . "</li>";
  }
  $html .= "  </ul>";
  $html .= "</div>";
  return $html;
}

Tags:menu

Related Articles

  • Make the Main Menu have dynamic links based on urlMay 31

    My main menu has links to common things: HOME | PHOTOS | VIDEOS ... etc. Home points to /, PHOTOS points to /photo-galleries and VIDEOS points to /videos The client has added a new feature request and I'm trying to figure out how to handle this. The

  • Drupal 7: How to create dynamic link based upon urlMarch 20

    I simply want a menu item which scans the url, grabs the second argument, and plugs it into the second wildcard location of the new menu item it's creating. So if the URL is: http://drupal.org/contenttype1/johndoe (johndoe = 2nd argument) the menu it

  • Hiding Menu Links Based on URLNovember 20

    Is there a way to hide menu links on the main menu based on the URL? For instance, if my URL is 'example.com/undergraduate', the main menu links would be different than if I were to go to 'example.com/graduate'. This obviously can't be too hard? A mo

  • Icon-based menu that dynamically changes based on permissionsMay 18

    We're trying to create an square grid, icon-based menu that is permission trimmed (certain icons appear based on your specific SP permission group), that dynamically rearranges the icons based on your permissions. Our requirements dictate that we mus

  • Page template dynamic links based on browser sizeSeptember 6

    I have a page template that links though to another php file to define what is displayed. The code for the page is - <?php /* Template Name: Portfolio */ ?> <?php get_header(); ?> <?php if(!is_front_page()): ?> <div id="pageHead&

  • Menu doesn't link to alias URLMay 10

    I'm having difficulty on a fresh Drupal installation getting the menu to use an alias (let's say "foo") rather than "node/#" link. The alias works when I type it straight into my browser. When creating the menu, I specified the alias (

  • How to make administration menu display child links without child urlMay 1

    My question is probably a little confusing, so I'm gonna explain with an example. Whenever I create a parent link like "admin/test/execute", the administration menu will display the link and if I create another link "admin/test/execute/log&

  • display dynamic content based on url slug on custom pageOctober 3

    i have a custom page named locations and i want the url to load like this: /locations/california /locations/nevada etc.. and upon each page load of the given url as above content is loaded based on it. So for example if California is loaded specific

  • Change Menu Item's links Dynamically, per page basisMarch 19

    I've been looking for this for a while, but found no solution. What I want is: Whenever someone visits to a user's profile, say http://mysite.com/user/1 there should be an item available in Main Menu, with the link: http://mysite.com/custom_module/1

  • Creating new dynamic menu including BP links July 31

    Perhaps I have missed something fundamental, but I am attempting to include the various dynamic menu items included with BuddyPress and other add-ons to my primary drop-down menu. For example, the Twenty Eleven WP theme has a tall header with a drop-

  • How can you create a dynamic link to a workflow initiation form in a workflow-based e-mail?May 23

    Process: User Creates Item Admin receives "approve this" e-mail with a dynamic link Admin selects dynamic link in e-mail Admin is taken to initiation form of second approval workflow Admin selects approval check box, hits OK, workflow updates st

  • Display different menu links based on page/themeJanuary 15

    I have a custom main theme for my website along with a Blog theme using themeswitcher. All content in my /blog directory uses the Blog theme. Question: I would like to display different links in the main menu when users are on my blog theme vs. main

  • Dynamic link in left navigation menuNovember 25

    We are using SharePoint 2013 on-premise. We have deployed a custom master page where we have removed the links for "One drive", "Sites" etc on the top right corner. We want to have a dynamic link in the left navigation menu in the my s

  • Menu Button that link to different pages for unique user?January 2

    Is there a way to create an menu button that link to different pages to each unique user? So far I have used the plugs-in: User Specific Content, Peter's Login Redirect and Them my Login. Basically, when an user login they can get information only av

  • Drupal 7 Menu Item without Link July 14

    We all know how clients are. We have a client requesting a parent link that has sub links. However, the parent link must not link to a page. Is there a way in Drupal 7 to do this? --------------Solutions------------- I am giving the Special menu item

  • How to show/hide a link based on a permission?July 28

    I'm looking for a way to hide/show a link from the main-menu if the current user has a specific permission. The menu item has already been created and the menu item links to a node that is controlled by hook_node_access(). --------------Solutions----

  • How to create dynamic link in views?September 12

    I am using views and I want to put a dynamic link in the header. The link is http://www.example.com/node/add/album/31 The number 31 varies depending which node it is viewing so I want it to change to whatever node id it is viewing. I'm not a coder so

  • How does the GPL static vs. dynamic linking rule apply to interpreted languages?October 6

    In my understanding, the GPL prohibits static linking from non-GPL code to GPL code, but permits dynamic linking from non-GPL code to GPL code. So which is it when the code in question is not linked at all because the code is written in an interprete

  • Hiding menu items dynamicallyDecember 20

    I am developing an application based on Drupal 7 and web services. Some application pages have a menu which should be customized (menu items should be removed) based on the response from the web service, but am not sure on how should implement it. In

  • Dynamic sidebar based on categoryJuly 13

    I am new to wordpress, i have developed a basic theme to make a tutorial web site, for that i need a dynamic sidebar based on category, suppose, i have category A & B, if user is on the A category i need to display A sidebar, if it's in B category ne

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 1.075 s.