I aim to create a view block that will display terms from a taxonomy vocabulary I have named "Categories", but here is how:

Each "category" term should link to a list. The list should display nodes that include "Category" terms, but these nodes must only be from the blogs' very own content type. Any other node that includes a category but isn't a blog node, won't be linked from that blog-categories list.

Does someone here a way to do so ?


At the start I tried to do that with contextual filters by Creating a taxonomy-typed view with a content relationship, filtered by a content type (contextual filter) and a taxonomy vocabulary (filter criteria). I tried several configurations for the contextual filter but with no success.

  • I searched with phrases like blog categories view Drupal and went about 10 articles but didn't find a satisfying answer.

closed as unclear what you're asking by kiamlaluno May 6 '16 at 5:23

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    there is no clear objective in your question, and even though you stated that you searched for the answers in google, it shows a lack of research. You should consider improving it after you've figured out what exactly you are trying to achieve – oksana-c May 3 '16 at 9:18
  • try this: in FILTERS add Content Type then check-mark Blogs. – No Sssweat May 3 '16 at 9:18
  • No @oksana-c, its not a lack of research; Its a fact that many complete solutions are ready for some Views, in a single Google search. These can be very efficient. – JohnDoea May 4 '16 at 5:24
  • I don't know if I understood, you want a block that shows all terms in particular vocab. Each term has a link to show all nodes from a particular node type. If this is it, I have something already working in a site that I'm developing right now. This envolves a bit of backend code. – Vagner May 6 '16 at 2:36
  • 1
    Still, you didn't ask any explicit question, so @oksana-c comment is still true. You need to say where you are stuck at, or you are going to get just answers each saying a different way to create a view. All of them would be equally valid. – kiamlaluno May 6 '16 at 5:23
up vote 1 down vote accepted

You need to create two separate views as they will have different base types:

View 1: Block

At admin/structure/views/add:

  • Show: Taxonomy terms, of Type : Categories
  • tick Create a block

Fields:

  • Taxonomy term: Term ID
    Tick Exclude from display
  • Taxonomy term: Name
    Untick Link this field to its taxonomy term page
    Rewrite results, Output this field as a link, Link path: blog-category-list/[tid]

NOTE: Taxonomy term: Term ID must be above Taxonomy term: Name

Sort Criteria:

  • Taxonomy Term: Name (asc)


View 2: Page

At admin/structure/views/add:

  • Show Content, of Type: Blog Entry
  • tick Create Page, add path: blog-category-list/% , Display Format ... list of fields

Contextual Filter:

Add filter Content: Has taxonomy term ID

  • When the filter value is not in the URL: Provide default value, Type: Raw value from URL, Path Component: 2

  • When the filter value is in the URL or a default is provided, Specify validation criteria: Validator: Taxonomy Term, Vocabularies: categories, Filter Value Type: Term Id


Variant 2:
To have a more friendly URL scheme you can make these alterations:

For the block:

Remove the tid field and change the Taxonomy term: Name rewrite field link like this: blog-category-list/[name]. DO NOT transform case

For the Page:

Alter the Contextual filter like this:

WHEN THE FILTER VALUE IS IN THE URL OR A DEFAULT IS PROVIDED, Filter value type, select 'Term name converted to Term ID. DO NOT select any transforms.

RE transforms: If you are certain that none of your terms will ever contain dashes, then you can do the following transforms:

Block: Rewrite Result link: tick replace space with dashes

Page: Contextual filter: tick Transform dashes in URL to spaces in term name filter values

You may also test the block link transform: Convert to lowercase.

You could create 2 views like so:

  1. A block view with a list of terms (taxonomy-typed view).

  2. A page view that accepts an argument, and uses it to filter and display a list of blog posts that share that argument, in this case a term.

Then rewrite the field display of the block view, for the term field– to link to the page view, instead... and pass the term as the argument.

  • I think I did something wrong in the process and didn't get you right. Can you please elaborate more and example, for instance, what type of argument you mean to? Is it a "Filter criteria" argument? Or another available with a "Contextual filter" ?, and also what method you mean to use when "rewriting the field display" ? Can you please edit the answer with these data? – JohnDoea May 4 '16 at 8:09
  • Bounty will be offered. – JohnDoea May 4 '16 at 8:09
  • The argument is the term name / term id, from the block view- that you are passing to the page view, to use as a contextual filter. Rewriting the field display is easy, in the block view- you have the ability to rewrite the output of any field. – user1642398 May 4 '16 at 10:12
  • Please edit and rephrase anything you need inside the question. A good answer will reward you in bounty, as well as acception and thumbs up --- All of this can be very good for you here, trust me. – JohnDoea May 5 '16 at 10:31
  • 1
    +1 This answer seems right but I agree it can do with a bit of elaboration – J. Reynolds May 5 '16 at 15:16

You could create a view that lists the blog content type with a term exposed filter that is available as a block. With Better Exposed Filters module you can show the exposed filter as links.

So overall;

1- Create a content view that lists blog content type
2- Add an exposed filter of the term field used in blogs
3- Set "Exposed form in block" to "Yes" (Advanced)
4- Display the exposed filter as links with BEF
5- Show the block whereever you want. ;)

When someone clicks on a link in the block, the filter will kick in and show all blogs with the related term.

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