4

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? :)

2 Answers 2

2

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.

1

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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.