How to display results tagged with just one term ID when there are multiple filters - drupal-7

I have a blog in Drupal 7 and used Views to display the fields. I have 2 sets of tags displayed on the sidebar:
1) SHAPES
Triangle
Square
Rectangle
2) COLOR
Red
Blue
Green
I created the 2 groups of tags via Structure > Taxonomy > Vocabulary > Add Term
For the View, I created one View with two exposed filters (similar to what was done in this tutorial)
VIEW:
Path: '/blog/tag'
Filter Criteria:
1) 'Content: Shape (exposed)'
Exposed form in Block: 'Yes'
Filter identifier: 'shape_id'
2) 'Content: Color (exposed)'
Exposed form in Block: 'Yes'
Filter identifier: 'color_id'
Exposed form style: BEF
The exposed filters are set to the appropriate block region in Structure > Blocks.
If I click 'triangle', only blog posts tagged with 'triangle' should be displayed. Then if I click 'red', only posts tagged with 'red' should be displayed.
It looks like the correct blog posts are being displayed when I click on the terms. The URL gets appended with IDs from both vocabularies, but I can't seem to get the right combos to display.
Desired URL when 'triangle' is clicked: '/blog/tag/?shape_id=1&color_id=All'
Desired URL when 'red' is clicked: '/blog/tag/?shape_id=All&color_id=1'
So, essentially the results should display items tagged with just one term ID.
However, how it is currently working is that if I click 'triangle', and then 'red', both 'triangle' and 'red' have the 'selected' class (are both bolded) and the url is: '/blog/tag/?shape_id=1&color_id=1'
The only way I was able to get the desired URLs is if I have the '-Any-' option displayed. However, the use case I have is to NOT have '-Any-' listed in the list of tags.
Is this even possible without '-Any-' listed in the list of terms? I have never used multiple exposed filters before, so any guidance would be great as I've researched this for almost a week now. I read in another post that contextual filters would allow me to create separate path aliases that are clean urls, but I have not been successfully able to do this.
Any help would be greatly appreciated. Thank you for your time.

I tried using the taxonomy term pages approach, but could not figure out how to get the fields displaying properly. The fields displayed were based on the teaser in my Blog content type. And using exposed filter option was not a solution since my use case was to only display results based on one tag. What worked for me:
1) Add new view to existing Blog View
2) FORMAT: 'Unformatted list'
SHOW: 'Fields'
3) FIELDS: [add fields that you need displayed]
4) FILTER CRITERIA: 'Content: Published (Yes)'; 'Content: Type (= Blog)'
5) PATH: '/blog/[YOUR VOCABULARY NAME]/%'
6) CONTEXTUAL FILTERS: 'Content: Has Taxonomy Term ID'
WHEN THE FILTER VALUE IS NOT IN THE URL: 'Display all results for the specified field'
WHEN THE FILTER VALUE IS IN THE URL OR A DEFAULT IS PROVIDED: select 'Override title' and in the input field, enter: '[YOUR VOCABULARY NAME]/%1'
select 'Specify validation criteria'
Validator drop-down, select 'Taxonomy Term'
Vocabularies: select appropriate Vocabulary name
Filter value type drop-down: 'Term name converted to term ID'
select 'Transform dashes in URL to spaces in term name filter values'
Action to take if filter value does not validate: select appropriate one that works for your needs (in my case: 'Display contents of "No Results found"')
If you need to display the term name in the heading on the results page, in the same view > HEADER > Add 'Global: Unfiltered Text' > then in text area, add something like "VIEWING RESULTS FOR [YOUR VOCABULARY NAME] / %1"
Save the View. Since I had multiple filters, I cloned the above view and renamed everything. So, I ended up adding 3 additional views to my existing Blog View.
I had previously set URL aliases for Taxonomy Term Paths, so I removed these
Also, I had to go back to my Taxonomy Terms individually and delete the URL alias that was generated from the pattern
To have the list of tags displaying on the right with the desired URL structure of /blog/[YOUR VOCABULARY NAME]/[YOUR TERM NAME], I created a separate new view:
SHOW: 'Taxonomy Terms' of type '[YOUR VOCABULARY NAME]'
Create a Block
'Unformatted list' of 'Fields'
FIELDS: 'Taxonomy: Term Name' > click this and unselect 'Link this field to its taxonomy term page'. Then expand "Rewrite Results" section and select 'Output this field as a link' > in the Link path: 'blog/[YOUR VOCABULARY NAME]/[name]' (the [name] at the end of the url structure should appear as you see it with the square brackets) > select 'Replace spaces with dashes' > Transform the case to 'lower case' > click Apply
FILTER CRITERIA: 'Taxonomy vocabulary: Machine Name (= [YOUR VOCABULARY NAME])'
Save the View
Then in Structure > Blocks, place the block in the appropriate region
Hope this helps someone!

Related

How to display all data from a paragraph field in views (Drupal 7)

I am currently a caretaker for a Drupal 7 website and I can't figure out how to group paragraph items in views. I have created a content type Products and one of the fields is called product variation which is field type paragraphs. I have created a paragraph bundle for that field.
Then I created a view to show the products on the front page. To display the paragraph fields I created a content relationship. When I open the relationship option and select delta to display one it only shows one and I can't get data from the others. If I select delta to display all it shows like in the image below (Current view displays like). The goal is shown on the same image. Could someone help me solve this:
My setup on the fields I want to display in the view are setup like this
`content-type: Products
product name - field type: Node module element
proudct image - field type: Image
product variation - field type: paragraph
paragraph bundle: product variations
color (Term reference)
view:
Display: product name, product image,product variation
Relationship: Content: product variation (field_product_variation)
Hopefully, someone can help me solve this problem.

Drupal 7 - assign several products (items) under each category

In D7, I have created a taxonomy (say categories) and set some terms (say category 1, category 2 etc) within it. I have also created a 'View' based on the 'categories' taxonomy and show the categories (category 1, category 2 etc) within the sidebar (block) of the website. Just let me know how can I assign several products (items) under each category so that site visitors can see the product lists on clicking a category from the sidebar. Basically I want to develop a catalogue based website to show products/items under each category.
Kindly help me in this regard.
Good morning,
If you have not done yet, you have to create a custom content type (Structure > Content Types > Add content type) and add as many fields as you need. When you are done, you have to add an extra field named Category, of type "Taxonomy Term Reference" (or something similar, I don't know exactly). You can configure this field so that you can assign several categories to a single product.
Once your contents are created, if you access the taxonomy term's URL, all contents assigned to that category should be displayed. However, you could also define a custom view that receives the name of the category as a parameter in the URL, and displays all contents in this category in a grid, table, list, ... whatever.
Hope it helps.

Drupal 7-Views Taxonomy Parent Child URL

Facing an issue with getting views to generate a proper URL similar to the way taxonomy allows me to click on a child term with the path: domain/term/artwork/mirrors (path alias is configured)
Vocabulary:
Product sections
- Artwork
-- Hand Painted
-- Mirrors
- Novelty
-- Ceramic Mugs
-- Stickers
-- Books
- Wearables
-- Shirts
-- Shoes
-- Personalized Shoes
I currently have a taxonomy view with 2 contextual filters: Content: Has taxonomy term ID (with depth) AND Content: Has taxonomy term ID depth modifier
Content: Has taxonomy term ID (with depth) is configured with...
• Depth: 1
• Set the breadcrumb for the term parents
• Display contents of "No results found"
• Specify validation criteria - Taxonomy Term from 'Product Category' vocabulary.
• Filter Value Type: Term name converte to Term ID
• Check Transform dashes in URL to spaces in term name filter values
Page Path: /category/%
With my current setup, I can go to: domain/category/artwork and this displays all content which is categorized under artwork (hand painted and mirrors)
What i need is domain/category/artwork/hand-painted but it displays all artwork regardless if its hand painted or mirrors.
BUT this path, domain/category/hand-painted works correctly. How do i make the url respect the parent term. It seems like views cant interpret a parent - child relationship.
I plan on creating parent term pages outside of this view so the parent term path /category/artwork won't be handled here.
Last thing to note is the node path pattern:
category/[node:field-category:parents:join:/]/[node:field-category:name]/[node:title]
• domain/category/artwork/hand-painted/fancy-painting
I solved my problem by adding the Taxonomy Views Integration module and specifying my existing view page.
-https://www.drupal.org/project/tvi
Next I had to modify the contextual filter to only have 'Basic Validation' and also remove "%" from the page view path.
Now the URL's are exactly what core taxonomy builds but it outputs the view i created
Hope this helps someone else! :-)

Drupal 7 Views: Term filter with relationship

I have 2 content types:
One content type is named: "Offer". This content type includes a reference field to choose one hotel, form the other content type: "Hotel". The content type "Hotel" has a term reference field called "sports".
Now I want to build a view filter, which uses the content type "Offer", and uses the sport terms which i get over the hotel relationship.
I already tried to create a relationship on my own:
Reference to the hotel
Added taxonomy field sport with the relationship to the hotel, which i created before
Then i added the taxonomy field to my filter, and selected the Relationship in the drop down menu.
But this doesn't work at all.
Anyone can help me?
Regards M.
The view should initially return the hotel content type.
Add a optional relationship to the offer reference field, this will give you access to the fields in the offer content type. Once you've done that you should be able to add whatever field you want as an exposed filter.
To get the sports working you may have to add the relationship Has taxonomy term in order to get what you want and then add the term as an exposed filter.
Use the patch over at https://www.drupal.org/node/1492260 for autocomplete.
A select list should work the same way as with this patch, but it's built-in. In either case, you have to enable it by checking the checkbox in the content type field config.

Drupal 7 - How to create a contextual filter based on an aliased url

CASE:
I've created a content type 'Attorney', and have set a url alias pattern for all attorneys to be 'attorneys/[node:title]'. I'd like to create a view that uses the aliased path to display the information about the attorney. This view should have a 'page' display.
EXAMPLE:
When a user visits 'http://mydomain.com/attorneys/aaron-silber' the view returns data for the Attorney with the name Aaron Silber.
BACKGROUND:
I've searched high and low for a solution to this but can't seem to find one that works for me. Typically I'm asked to create a page view with a url of 'attorneys/%' and add a contextual filter with 'Content: Nid', choosing to provide a default value (type: Raw value from URL, path component 2).
The resources on the web for this case are aweful at best. Lets try to fix it here once and for all.
Thanks!
Use a Views block instead with the visibility set to "Only the listed pages" and supply "attorneys/*" in the textarea. Set the block to display in the main content region. Use the Content: Nid filter with a default value of path component 2, as you were previously attempting.
You can't have an attorney node page and a Views page occupying the same URL.

Resources