0

I have created a view for a content type called "events," and in the view there are 2 contextual filters (by category and years).

what I want to do is to be able to view the result in 3 conditions:

  1. only the year: http://example.com/events/2010
  2. only the category ID: http://example.com/events/4
  3. year and category ID together: http://example.com/events/2010/4

Now the problem is that in the second case, as the argument is considered a year.

How can I set the view to be able to use a URL as in the second case?

1
  • What do you do when the category id is 2010? You can't really do it like you suggest without doing custom code and risking things breaking.
    – googletorp
    Aug 20, 2011 at 15:34

1 Answer 1

2

As @googletorp commented, the argument in the url have to keep a certain order if not Views won't know which kind it is. The recommended method for this is allowing a "wildcard" by providing an exception, in views you can configure this in the contextual filter options: contextual filters default arguments
Then you simply put all instead of the year when not it's not available:
2- the category id alone : http://mydomain.com/events/all/4

2
  • Don't understand what should be entered instead of 'all' in the textfiels "Exception value" Aug 22, 2011 at 7:57
  • You just leave it as "all", then when you want to display the events for every year in a specific category you just call this URL: http://mydomain.com/events/all/4. Renaming this parameter allows you to localize it, for example: http://mydomain.com/events/todos/4 in spanish.
    – tostinni
    Aug 22, 2011 at 16:40

Your Answer

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

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