0

I'm currently using a view to display content teasers and I want my users who are making pages to be able to incorporate these views, however I want them to be able to specify a taxonomy term to show that content. I tried doing this with a Contextual Filter, however I need some way to allow the user to specify the term in the page editor, not on the page preview itself. Is this something that Views allows you to do? Do I need to install a module, or do this programatically?

Hopefully I'm not being too confusing with that description, if so just let me know and I can try and clarify.

2
  • To clarify - you want users to create nodes, and on those nodes they will select one taxonomy term. Then when they save the node, besides the usual node content you also want to show View of Content teasers you have created, but only for the content that shares the same taxonomy term as the one the user selected on the node. Is this true?
    – prkos
    Commented Jun 12, 2018 at 23:59
  • @prkos Yes exactly. Without creating individual views for each term. I just want one view that will filter based on a term they provide somewhere on the page. Commented Jun 13, 2018 at 14:06

1 Answer 1

0

There are two parts to this question - one is to have creators of nodes to choose a Taxonomy term, the other is to have a Views Display show up on Node View based on the Taxonomy term set inside the node.

Taxonomy term reference

As you've already worked out, the easiest way to allow for users to influence what content list to display on their nodes is to allow them to choose a Taxonomy term.

You can do that by creating an Entity reference field referencing Taxonomy terms. The way you worded your question suggests you will only allow one term to be selected (limit number of values to 1).

When the node is saved, the information about the chosen Taxonomy term will be displayed when viewing the node. If you don't want this to be visible, if you only want this field to serve as a way to influence Views in the following steps, you can hide the field from showing up on node view by changing Manage Display settings. The info from the field will still be available for Views to read "on the sly".

Views Block listing content sensitive to the Taxonomy of the page they're on

Creating Views that display related content is probably the most common request in Views. With such a Views Block you don't have to have any additional interface for node creators to choose what to display on their nodes. Simply having a Taxonomy term reference is enough (already covered above).

First you create a Views Block listing your desired Content (set up all the regular Filters and Fields).

Then add a Contextual Filter of type Content: Has taxonomy term ID, and configure it to Load filter from node page (NOT taxonomy term page). Take a look at screenshots from this answer: display lists of related content that share the same Taxonomy term.

In the end place the Block in a region, and configure the block settings (to display only on node page where you want).

When your content creators save a new node, that Block will automagically show only Teasers of content tagged with the term they chose when creating the node.

If the content type of the created node is the same as the content type of teasers in the Block, the newly created node will also be displayed on the Teaser list. If you don't want the node you're currently viewing to be listed there you can exclude it with an additional Contextual Filter Content: ID (Provide default value: Content Id from URL, More (at the bottom): Exclude).

2
  • THANK YOU! We've been trying to do this for 24 hours at work! This was exactly what we needed! Thanks again for your help. Commented Jun 13, 2018 at 15:35
  • I'm glad to help :)
    – prkos
    Commented Jun 13, 2018 at 16:35

Your Answer

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

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