0

TL;DR, Below are the structure of content types, paragraph types and taxonomy in my site.

Taxonomy vocabulary - Category

  • Terms - Sports, Politics, Business

Paragraph type - Multi Article

  • Fields -

    • Category (term reference to Category vocabulary)

Content types - Landing page , Article

  • Landing page (fields) -
    • Multi category (Paragraph field referring to Multi Article paragraph type)[unlimited]
  • Article (fields) -
    • Category term (term reference field to Category vocabulary) [unlimited]

Sample content example -

Landingpage A paragraph field has Sports,Politics

Landingpage B paragraph field has Politics

Landingpage C paragraph field has Business,Sports

Article A is tagged with Business

Article B is tagged with Sports,Business

Article C is tagged with Politics,Sports

Desired output -

Landingpage A detail page should be showing something like -

Sports [based on paragraph field]

  • Article B [based on term reference]

  • Article C [based on term reference]

Politics

  • Article C [based on term reference]

Landingpage B detail page should be showing something like -

Politics [based on paragraph field]

  • Article C [based on term reference]

Landingpage C detail page should be showing something like -

Business . [based on paragraph field]

  • Article B [based on term reference]

Sports [based on paragraph field]

  • Article B [based on term reference]

  • Article C [based on term reference]

Can this be achieved with views and contextual filters ?

Question in detail - Forgive me for a lengthy question.

I have a field in the content type - Landing Page, which refers to a Paragraph type.

The paragraph type intern has a term reference field.

When I edit/ create a Landing page content, the desired term names are selected and saved (it can be any number of terms and it doesn't mean that this landing page is tagged to these terms. This is done just to categorise the result while rendering).

I also have another content type - Article which are actually tagged to some terms (both the above paragraph term reference and Article term reference are of same vocabulary)

Now, when any of the landing page content is rendered, I would like to show the latest 5 (or any number) Article contents tagged with each term that was added to the paragraph field which was selected from the paragraph field earlier.

The idea is to make the view result dynamic based on the terms added in the paragraph field of the content. In other words, the view result should vary on every node detail page.

Is there a way to achieve this with the help of views ? My final hope if I don't find a solution is to programatically fetch the latest contents under each term and display them. Would like to know if a better more elegant way is there with views.

Note - The reason why Paragraph is chosen is due to the flexibility it provides with rearranging the terms etc.

Would be great if any reference or examples are provided if my approach is right. Thanks. Paragraph field screenshot

1

Although there are multiple ways of doing this, here is probably one of the better ways if editor/front-end control is what you are after. These days, paragraphs are pretty commonly used to give easier control to editors.

It will be setup a little differently however.

  1. First, install and enable the block_field module. This will create a new type of reference field. We will use this later on.
  2. Create a new View, choose Block display. Choose the Article bundle for your content. Add some fields from Article that you want to see. Add a new basic filter criteria for the category term reference field. Set its default value to Sports.
  3. You should now have a view showing all articles where the category contains sports. Now duplicate this sports block, make another block for politics, and so on. Changing the filter criteria to match each term. enter image description here
  4. Your view should have a few blocks in it now. One for each term. Now go edit your Multi Article Paragraph type.
  5. Delete your term reference field from the paragraph, and add a new field. Under references you will see a Block (plugin) now. Choose that. Name it whatever, set to unlimited. enter image description here
  6. On your new field, at the very bottom, drop down the Blocks fieldset. By default every block will be checked, uncheck them. Scroll down until you see your 3 view blocks you made. Check each of them. Then save the field. enter image description here
  7. Now go create a new landing page as if you are an editor. Your Multi Article paragraph will have a block reference. Choose add block, and pick one of the view blocks. Add a paragraph item for each view block you want to display.

enter image description here

You can then make many landing pages, allowing the editor to choose which types of articles to display. Here is my landing page A.

enter image description here

  • I tried with the approach that you suggested, but no luck with the desired result. Maybe I was not clear with what exactly the result should be. The one limitation which I see is the view result is constant here, and I need mine to be dynamic based on the terms added in the paragraph field per content. In other words, view result should vary with node. The whole idea is to give the editor whole control over what should be displayed instead of filtering the terms from the view settings. Thats the reason Paragraph field is added to the content type. Edited my question. Hope it's clearer. – wilNev Jan 3 at 8:38
  • Ok, Ive updated my answer with a new approach. – Matt Campbell Jan 4 at 17:40

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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