1

I have vocabulary "City":

  • New York
  • London

and vocabulary "Places" i.e.:

  • restaurants
  • cafes

The menu link is, e.g. mysite.com/london.

When a user click on a tag, e.g. cafes, I want the term city term to stay them same in the url mysite.com/london, but to add the places term on the end, e.g.: mysite.com/london/cafes in London, so that it only shows cafes. I.e. not mysite.com/cafes, which will show cafes anywhere in the world.

How can I do this please?

  • Drupal 7? How are you currently displaying the places terms on the city term pages? Meaning, are you using a taxonomy term menu block in a sidebar, or perhaps a unordered list of places terms generated using a view? Does it matter? – Jason Apr 16 '14 at 14:22
  • Thank you for your message. I'm using Drupal 7. I'm not using using a taxonomy term menu block in a sidebar. I using unordered list of places terms generated using a view. every listed item has it tags i.e cafe, parks. When tags are clicked they need to show the i.e all cafes in site.com/london/cafes but instead goes straight the the term site.com/cafes.... Many thanks again for your help – user3350619 Apr 16 '14 at 15:20
  • Is this view a taxonomy term view using a view block display? Are you using panels or just views and blocks? – Jason Apr 16 '14 at 17:58
2

I think you will need the following setup to work. I'd test this extensively, as it seems somewhat fragile.

a) Prefix your city taxonomy path alias pattern to something like 'cities/[term-name]'. You can't create a view page with a path that starts with an argument.

b) Add another view (you may want to disable the default tax term view or alter the default taxonomy term view ) with 2 contextual filters, 1) Content: Has taxonomy term ID set to provide default value (raw path using 2 component and alias) restricted to the city vocab. and 2) Content: Has taxonomy term ID set to provide default value (raw path using 2 component and alias) restricted to the places vocab.

These contextual filters will share these settings: in the validation criteria, Filter value type set to 'Term name converted to Term ID' and tick the 'Transform dashes to URL to spaces in term name filter values' checkbox.

For the second contextual filter, set 'Action to take in filter value does not validate' to "Show all", which will allow you show all results when viewing 'cities/london'.

Note, using this technique can be problematic if you anticipate any of your terms containing apostrophes, b/c the path alias for a term with an apostrophe can be name-s-something and this won't be converted to a term id.

c) Then, you'll need to alter the link generated by your existing unordered list of places view. Not sure how to go about this in the UI alone. If you share your exported view code, I'll take a look. If you can, you could create a view field template file to retrieve arg(0) and arg(1) and then use those results to generate the link in the template file.

  • I've found out how to alter the link like this function MYTHEME_preprocess_node(&$vars) { if (array_key_exists('content', $vars)) { $content = &$vars['content']; if (array_key_exists('field_photo_topic', $content)) { foreach ($content['field_photo_topic']['#items'] as $index => $info) { $tid = $info['tid']; $content['field_photo_topic'][$index]['#href'] = 'photos/' . $tid; } } } } – user3350619 Apr 18 '14 at 13:22
  • Always more than one way to skin a Drupal cat! Glad you have it working. – Jason Apr 18 '14 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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