4

I have a content type article and when editing an article there should be a field where you can select a taxonomy term of a specific vocabulary.

When viewing the article it should show a list of titles of all articles associated with the selected taxonomy term. I know how to make a select field and also a view to show the titles. But how do I send the selected term to the view and how do I display the view in the article?

2 Answers 2

6

1) Create a View block, when you create it use Show: Content.

2) Under Advanced Contextual Filters add Has taxonomy term ID

3) Select provide default value Type: Taxonomy term ID from URL (this will automatically grabs the term from your node) If you want, you can limit the terms by vocab.

Even if your tax term reference field is limited to 1, maybe you should set it up as if it was unlimited, in case your client later wants to allow more than 1 value.

Change the multiple-value handling option to the 2nd one, share any term.

Scroll down to MORE and check mark allow multiple values.

enter image description here

Click Apply, to save the settings.


Now you want to exclude the current Article (node) from the list. No point in showing the Article the visitor is already viewing/reading.

4) Add another contextual filter of ID

5) Provide default value Type: Content ID from url (automatically grabs the ID from your node).

6) Scroll all the way down, and click on MORE, and check mark Exclude.

enter image description here

So your Advanced section should look like this:

enter image description here


To place the block in your article, there are several ways.

Go to admin/structure/block and click on Place Block, search for your View Block and click on Place Block.

In the configuration, under Visibility settings, select Content Types and check mark your content type.

enter image description here

Site Note: There are other ways to insert/place your view:

  • Through a template file.
  • Using Panels and or Display Suite (Note: I am not 100% sure on this as I have not played much with these modules in D8, in D7 I know you can).
10
  • Wow, this is amazing thank you! What would have to be changed if there was the possibility to select more than one taxonomy term on the content edit page?
    – 0711master
    Jan 8, 2017 at 14:13
  • I am on mobile ATM. I'll update the answer later. In step 3, you sroll down and click MORE and check mark Allow multiple values.
    – No Sssweat
    Jan 8, 2017 at 14:29
  • It doesn't work, now it doesn't show any titles
    – 0711master
    Jan 8, 2017 at 17:26
  • In step 3, change the multiple-value handling option to the 2nd one, share any term.
    – No Sssweat
    Jan 8, 2017 at 17:37
  • 1
    Ok, I found my mistake: I was adding the block within the taxonomy term view instead of creating a new view. Thank you for your effort!
    – 0711master
    Jan 8, 2017 at 22:39
0

Regarding the placement of the block, I found another interesting thread: How to create a field that references a Views Block display in D8?

So I tried using the modules

1) "Views Reference Fields", so you can add a field to a node to insert a specific view, especially in conjunction with Paragraphs. Unfortunately it didn't show anything on my test site. Also with Paragraphs you have to save the node and reopen before you can select a display of the selected view.

2) "Block field", so you an add a field to a node to insert a block, which can also be a block of a view. It worked for me with and without paragraphs.

Your Answer

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

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