I have created a taxonomy vocabulary 'City' and add some term under this vocabulary like as city1, city2 etc...
I have Created a content type named "Student" having fields with a term reference field of that taxonomy vocabulary 'City'.
Can I pass URL alias of Taxonomy term in a view so that when I check the URL http://www.example.com/city/city1, it should displays all the nodes assigned to this taxonomy term, so the alias works perfectly.
Follow the simple steps to achieve this structure through view:--
- 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" 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" next to 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 all taxonomy pages of vocabulary City.
Navigate http://www.example.com/city/city1 url_alias of term city1, this will display all nodes related to the taxonomy term city1.
Note:-- We can not directly pass url alias of a taxonomy term in a view as an argument.
Since "Taxonomy path alias == taxonomy/term/%".
So, 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.example.com/city/city1 i.e your taxonomy term path, term ID will pass as an argument since the block view has assigned on all taxonomy page of City that will display all nodes related with city1 taxonomy term.