Hi all - It would be great if someone can help me with the following as I've been scratching my head to come up with a good solution:

I have a taxonomy and in that taxonomy have the following terms

Bits n' Pieces
Bits & Bobs
Bits, Bobs & More

I'm using Path auto to re-write the URL aliases of these to be:

bits-n-pieces
bits-bobs
bits-bobs-more

Now, what I want to create is a view with a contextual filter so that when I go to http://www.site.com/samples/bits-n-pieces the first item in the taxonomy list above will be found as a match and any content that falls under that taxonomy will be displayed.

From what I understand I can filter a view using a contextual filter that chooses a taxonomy Term ID or Term Name - both of which really aren't appropriate with the way my URLs are structured.

So basically, how can I use the taxonomy URL alias as an argument to filter a view?

Thanks in advance!

Comments

spovlot’s picture

Views comes with a "Taxonomy term" view (disabled by default). This view overrides the default URL of /taxonomy/term/% which is aliased by your PathAuto settings. So, you can enable and modify that view as you like. It already includes the necessary contextual filters for the terms.

craigperks’s picture

Hi,

Thanks for the comments. We've tried this view, which filters by Term Id / Term Name by default and it doesn't really work as we want. We want to be able to filter content using the path generated for taxonomy terms.

The problem my colleagues and I have is that pathauto is stripping out (and rightly so) ampersands, commas and other illegal charachters. When I then use this view to check the Term Name against what is the pathauto because these symbols are then missing the match fails and the view doesn't work.

Thanks,
Craig

spovlot’s picture

Craig,

I suggest you look at this again. Even though this is an alias path, the actual path is available in the contextual filter. There is no need to pull the term name out. Path "/vocab1/my-term" == "/taxonomy/term/3" and the taxonomy view that points to /taxonomy/term/% takes the term id for the contextual filter. So, when you view "/vocab1/my-term" you will see the view results. I think this is what you want.

Scott

F.G’s picture

I became crasy with this thing. Can someone telling me, How to fill all neccesary paths with a sample. If i use the same path that my view with taxonomy, i have a white page. if i change the path of taxonomy, my contextual view work again.

spovlot’s picture

Did you try using the default taxonomy view provided with Views? What path did not work? What path did?

F.G’s picture

No, i did'nt use the default ( i didn' knew it) when i made my personnel view with a lot of configuration.

So i try to use it's path, in a second time ( recommanded by a guy because, i was asking the way to override the link of my taxonomy menu :o( on irc. So actually i' ve broken all. Does i have to add something else with the path in my personnal view. i notice strange things too.

my view path/ = /books
pathauto module.
my default taxonomy /books/[term-name]

if i left the same path, i have a default display, not my view.

So if i remove the pathauto and create a basic link like /books/history for example, i saw my filtered view.

in a second try, i tried to change my view path with the same that default taxonmy view, but at the end, same trouble. So i ll appreciate a sample, because i'm ready to jump by the window. Sure, i'm messing a small thing.

i just want that taxonomy term have this link.
books/history, books/xxx, books/yyyy mapped to to my view. I'm not sure about taxonomy pathauto.

Regards.

spovlot’s picture

You have to override the underlying path of /taxonomy/term/% in your view instead of /books.

As I mentioned in the issue earlier, you can enable the sample view for taxonomy provided by the Views module as a starting point.

F.G’s picture

are you telling me that i can't target my view with a custom path ?

spovlot’s picture

You can't override the same path with both PathAuto and Views at the same time. So, you can either override the underlying path of /taxonomy/term/% instead of /book/your_term OR remove the PathAuto alias

AJen’s picture

This whole concept has been causing grief for quite some time.

I now understand that it's the system path you use in the view and then you are overriding that by using the path alias eg.

node/% is used as the path in views
Then pathauto sets up an alias for node/nid changing it to category/article-name

eckroth’s picture

babusaheb.vikas’s picture

Hi craigperks,

Follow the simple steps to fix your problem:--

1) Install https://www.drupal.org/project/disable_term_node_listings module.
2) Edit your taxonomy, URL like as /admin/structure/taxonomy/Yourtaxonomyname/edit
3) Select "Disable node listing for all terms" like as https://www.drupal.org/files/project-images/disable-listings-preview.png and save.
4) Create a block view of your content type, filter a field title, body and whatever you want to show like as normal view.
5) Pass term reference field(of content type) from Contextual filters.

5.1 Select "Provide default value" under When the filter value is NOT available
5.2 Select "PHP Code" next to Type
5.3 Enter "return arg(2);" under PHP contextual filter code textarea.

Now, a block view of your content type has been created.
Assign that view on your all taxonomy pages.
this will display all nodes related to the taxonomy term when you open/navigate taxonomy url_alias.

Note:-- We can not directly pass url of a taxonomy term in a view as an argument.
In above steps 5.3, I have passed "return arg(2);", which return the term ID of a taxonomy term.
When you check the URL http://www.site.com/samples/bits-n-pieces i.e your taxonomy term path, term ID will automatically pass as an argument and it will return all nodes related with that taxonomy term.

Vikas kumar

colan’s picture

You actually don't need to do any of this. Follow the instructions in #2415649: URL alias in Taxonomy term not being converted to ID.

B00StER’s picture

These instructions do not work with url-alias of the taxonomy term. They only work with taxonomy term name (as they supposed to).

quinns’s picture

Late to this thread but for anyone who comes across this in the future, I think this module will help https://www.drupal.org/project/view_alias