3

I have two taxonomies on my site that need to be browsable independently using different Views. Therefor I decided to prepend the term paths with the vocabulary name. In PathAuto patter section I have defined:

[term:vocabulary:name]/[term:url:path]

and the paths look the way I want:

vocabname/taxonomy/term/tid

however the Views don't work. The pages that are generated for the path

vocabname/taxonomy/term/%

somehow won't jump in. I see the error that no content has been tagged with this term, whereas the view should display teasers of the children terms.

So, do you think there is a wrong assumption on my side as per the url aliasing process (what occurs first)? Should that work?

1

Yes - you're very close on this, but you're right that the pathauto path is not being recognized by views here. To overcome this, you're going to need to add a 'default argument' in your views argument handling code and use PHP code to pass the term id from the end of your string.

It looks like from the version of tokens you are using that you're on Drupal 7 / Views 3, correct? If so, you're going to want to add this under

Contextual Filters --> Content: Has taxonomy term ID --> Provide Default Argument --> PHP Code

and then in the php code section add this code:

$path = isset($_GET['q']) ? $_GET['q'] : '';
$path = explode('/', $path);
return $path[3];

This gets the current path as an array and returns the 3rd element, or the TID and passes it to your view.

  • Thanks Schnippy. You were right bout the versions. I used your snippet, with a little alteration though - the Contextual filter has to be here "(Parent) Taxonomy Term (Term ID)". Nonetheless, the View does not get triggered at all (no global header, no gear icon)... Speaking in plain language: there must be some kind of a conflict between Views URL and PathAuto which causes Views not to see that it should play under this path rather than let default taxonomy viewer in. – Artur Dec 27 '11 at 8:36
  • What's more: the view works expected in the Preview pane, even without your code :( So looks like the path is kinda obscured from Views – Artur Dec 27 '11 at 9:33
  • Artur - when you say it works in the preview pane, are you manually passing it an argument through the views preview interface? Another suggestion -- in the contextual filter settings, under 'When the filter value IS in the URL or a default is provided' -- override the title and add this argument in as %1 to determine whether or not the argument is actually getting intercepted by the above added code or if its a problem elsewhere in the view. – schnippy Dec 28 '11 at 20:39
  • Thanks again, as I learned form the maintainers of Views, Views knows nothing about pathauto aliases and it's no wonder that my URLs are not intercepted. I had to resort to Taxonomy Display to get Views working the way I wanted. – Artur Dec 28 '11 at 23:36
1

OK, so in case someone runs into the same problem. It was my fault. Taxonomy Display works just great. It distinguishes the vocabularies and my PathAuto patterns did not need to be touched. The only thing I had to watch out for was providing default value for the contextual filter in the views responsible for listing final content nodes. Default value should be taken from URL as Taxonomy ID. That's it.

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.