2

I have created a taxonomy named Category which has a number of terms like Agriculture, Business, Computers, etc.

I have created three content types viz. Products, Suppliers and Buyers. All of these types use the terms from the Category taxonomy.

What I am trying to do is create a block named Supplier Categories which as the name suggests, displays a list of terms from the Category taxonomy which are associated to Suppliers. So say if you have Suppliers associated to the Agriculture and Business categories then this Block should show them. It shouldn't show Computers though because no Supplier uses this term.

I am not sure whether this is possible or not but I have spent a lot of time playing with blocks but I couldn't get it to work.

By the way, I am trying to do this using Drupal 7.

  • Why do you need to show it in a block ? If it is part of the content type (specific node), you could easily list values in that node. If you want to show these in a block, you must program block to show terms associated with currently viewed node. – NenadP Oct 13 '12 at 17:41
  • I am not sure but I think you have misunderstood what I am after. I want to use a block because it's going to be displayed on the sidebar. What's displayed here isn't going to be changed depending on the 'currently viewed node'. It's always going to be the same. It is going to show all terms from taxonomy Categories that are in use by contents of type 'Supplier'. So taking into consideration the example I gave above, it should display the categories Agriculture and Business but should not show the category Computers. – VCore Oct 14 '12 at 7:02
  • So your block only needs to output terms of vocabulary, am i correct ? – NenadP Oct 14 '12 at 8:47
5

You should use Views. Here are the steps to do to achieve what you would like to do:

  1. Create vocab. "Category":

    Category vocab.

  2. Create content type "Suppliers" with a "Term reference" field to "Category" vocabulary:

    Suppliers + Term reference

  3. Create three "Suppliers" contents in "Agriculture", "Business" and "Blabla" categories - so these 3 should be listed in your block.

  4. Add a new view at admin/structure/views/add with these settings:

    add new view with block

  5. Add a new field "Content: Category":

    field Content: Category (here are the settings)

  6. Remove "Content: Title" field (1 , 2)

  7. Set some descriptive names (like machine name, block name, display name, etc.), AND set Sort Criteria to "Content: Category (asc)":

    descriptive names, sort criteria

  8. Save

  9. Go to admin/structure/block, set "Supplier Categories block" to be displayed in the "First sidebar" (or "Sidebar first" in Bartik) or any other, then hit "Save blocks":

    admin/structure/block

  10. You are ready.

    Supplier categories

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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