Hi,

This seemingly easy task has got me stumped - please help if you can! I've been searching Drupal for an answer for ages with no luck... I want to have a block on the taxonomy term page which displays a terms siblings (those that share the same parent).

The easiest way to do this would probably be by using Views, but I cannot figure it out.

The example is this: I have countries, regions and counties in my taxonomy:

England (country)
- South West (region)
-- Devon (county)
-- Somerset (county)
-- Cornwall (county)
-- Dorset (county)
- South East (region)
- East Of England (region)

etc etc etc

When On the ' Devon' term page, I want to display a View containing all the other counties in that region - eg a block containing links to Somerset, Cornwall and Dorset.

I have no problem displaying children through using relationships, and also can display parents without a problem - but am struggling with siblings.

This is for a 'term' style View.

Any help much appreciated,

Joe

Comments

itangalo’s picture

Me and a colleague spent some time discussing and trying this out. (Or, actually, we were looking at http://drupal.org/node/1084402 – but I accidentally found this thread too.)

My conclusion is that it is probably not possible to do this with Views, if you don't want to custom code a default argument (which I consider pretty bad practice).
However, it is pretty easily done if you can manage contextual information and arguments with a tool like Page manager (http://drupal.org/project/ctools), probably in combination with Panels (http://drupal.org/project/panels).

If you want to list all content in sibling terms, then you want basically the following:

  • A node view with...
  • ...a relationship "Taxonomy: related terms", fetching all terms in the relevant vocabulary. (This should really be called Taxonomy: Terms in node, and is the first of the two relationships with the same name.)
  • ...another relationship "Taxonomy: parent term", using the related terms relationship to fetch the parent of the relevant term.
  • ...an "Term: tid" argument, making use of the parent term relationship.
  • ...and optionally also an argument "Term: tid" making use of the terms in node relationship, and using the option "exclude from display" to not list any nodes with the given term.
  • Then, to give the view relevant arguments, you will need a custom page from Page manager, with...
  • ...a context object "Term", fetched from the node you're looking at (or simply being the term you're viewing).
  • ...another context object "Parent term", fetched with a relationship from the term above.
  • ...an embedded view, preferrably using the display type content pane, that can be embedded in Panels, and that takes the parent term tid as the first argument and optionally the starting term tid as the second argument.

It seems kind of silly that you would have to do all of this just to get siblings listed, but I think you really have to as things are right now. You could get rid of the Page manager stuff if you are willing to use custom PHP to load default arguments. You could probably do all of this much smoother if there were a Views relationship that gives you children for a given term, and not only parents.

If you used a taxonomy view instead of a node view, the approach would basically be the same – but you wouldn't have to create the first relationship from node to taxonomy term(s).

I hope this might be of some help. Good luck!
//Johan Falk, NodeOne, Sweden

joecanti’s picture

Hi Johan,

Thanks for replying - that is really useful yes. I didnt realise you could pass arguments into Views like that. I use panels a lot so it makes sense for me.

I ran through your explanation, and got it working - I used a mini panel to place the view on a page, but I was a bit stuck on how to make the term dynamic according to the URL.

So the solution for me was to create a quick View which got the term from the URL, and then use that View in the mini Panel context, and then add the term:parent relationship. Basically replace the static term context with a dynamic View context.

And it works! Amazing. Thanks for your post - that did the heavy lifting and got me on the right track. Im still not sure exactly how it works, but I've learnt to leave that side up to the Drupal masterminds!! I dont know how merlinofchaos came up with this stuff, but it's impressive. Views and Panels is my main reason why Drupal is number 1.

Thanks alot for your help, after hours of head scratching I can now resume my life :-)
All the best, Joe

itangalo’s picture

Great news! Thanks for taking the time to write back with positive feedback.
Happy Drupalling!
//Johan Falk, NodeOne, Sweden

ralf.strobel’s picture

In Drupal 7.x you could use EVA. It lets you place a view on any entity page as a field, while importing any content-related tokens as arguments for Views.

Another module, Entity API, gives you current field values (including taxonomy term references and their parents) as tokens.

So all you need to do is create a view of terms with a parent filter, using the page's own term-parent as input.

rwilson0429’s picture

subscribing

ReggieW

fadgadget’s picture

hello ralf i was hoping to achieve this with EVA. Show 'sibling' terms. Does anyone know what the filters etc i would need to add? Ive tried most things.

thanks

rwilson0429’s picture

This can now be quickly and easily in Drupal 7 using Views 3 module and Panel's Page Manager module. A Taxonomy Term View is included with the Views 3 module (use it) and, Panel's Page Manager module can consume this view's output, as well as, pass contextual filters (arguments) to the view. Views and Page manager are a very powerful combination.

First, Setup the Taxonomy Term View:
I was able to get the sibling terms to display by adding two contextual filters and two relationships to the Taxonomy Term View Master display. You can probably use displays other than the Master display to accomplish. The 1st relationship I added to the View was 'Taxonomy Terms on Node'. The 2nd relationship I added was 'Taxonomy Term: Parent' and set it's relationship to 'Term on Node'. I also setup contextual filters 'Content: Has Taxonomy Term ID (with depth) and 'Content: Has Taxonomy Term ID depth modifier'.

After the Master (default) display is configured, create a Views Content Pane display to displays the nodes that have taxonomy terms on them. This display will use the default contextual filters and relationships from the Master display. Of course, if you did not setup the contextual filters and relationship on the Master display, you can try to set them on the content pane configuration page.

To enable Page Manager to pass arguments to the View's Content Pane, you should edit the Content Pane's 'Argument input' and set the data source for the view arguments as follows:

  • Content: Has taxonomy term ID (with depth) source = 'from context'
  • Required context = Term ID
  • Content: Has taxonomy term ID depth modifier source -> 'From context'
  • Required context -> Parent term

Next, Setup Page Manager:
Why reinvent the wheel here, the Panel's Page Manager module includes a Taxonomy Term Page. So, there is no reason not to use it. Enable the Page Manager's Taxonomy Term Page and create a variant.

  1. Complete the 'General' settings as you desire.
  2. For now, you don't have to worry about the Selection Rules. Your View will take care of most of this. You can go back and tweak the selection rules later.
  3. No need to bother with the Context pane, it already has a relationship 'Taxonomy vocabulary from Taxonomy Term'. Again, you can tweak later.
  4. Select a layout from the Layout pane. Select a layout other than the one column layout since you will be displaying related siblings. I suggest trying one of the two column layouts at first.
  5. Add your View Content Pane that you created to one of the layout regions in Page Manager. Once you click 'add content' you should see your View Content Pane as one of the contents that you can add to the region. If you don't see it, see tip below.
  6. Now, in another layout region, click the cog to add content and under the Add Content display, you should see 'Taxonomy_Term'. click it and select 'List of Related Terms'. The List of Related Terms should be configured for 'Term being Viewed' and then under 'Which Terms', select Sibling Terms.

That's pretty much it. This was accomplished using D7.9 and the latest dev versions of Views3 and Panel's Page Manager modules.

Tip: Hopefully, someone will provide a better way to get Views Content Pane to Display in Page Manger, but this is how I get it done. If you don't see your View's Content pane in Page Manager, first make sure that you configured Page Manager to make new content automatically available to be added to Panel pages (admin/structure/panels/settings). If your View's Content Pane is still not showing up in the Page Manager's Add Content display, go back to the View's Content Pane and set the Argument input for 'Content: Has taxonomy term ID (with depth) source' to None (Remember, the settings because you will have to come back and change them back again). Save the View. Now, go to Page Manager and the View Content Pane should be listed. Add it to your desired layout region, click update and save, return to Views and set the Argument input value back to 'Content: Has taxonomy term ID (with depth) source = 'from context' and Required context = Term ID. Save the View.

ReggieW

nobunaga-dupe’s picture

To enable Page Manager to pass arguments to the View's Content Pane, you should edit the Content Pane's 'Argument input' and set the data source for the view arguments as follows:
http://www.stopfinger.com/goods_c3BlY19pZAk2MjM2.html

JCB’s picture

I had a similar problem to display sibling/child terms of current term page (parent term).
Tried Taxonoomy Sub-Terms; however, it was not enough as I also wanted to display the count of each term next to it.

I ended up searching through any post I could find, which had anything related to sub-terms, child terms, parent terms, etc.

My problem was solved with views.

Here is my setup:
I installed/enabled Hierarchical Select and set the configuration to.
1. "Save term lineage".
2. Save values additionally to the core taxonomy system (into the 'term_node' table).
This automatically applied the "parent" terms to the nodes as well; which resulted in the functionality you are looking for.

I then created a view:
Relationships: "Taxonomy: Parent term"
Arguments: "(Parent) Taxonomy: Term ID" - uses Parent Relationship.
Action to take if argument is not present: "Provide default argument" --> Taxonomy Term ID from URL and ticked "Load default argument from term page".
Fields: "Taxonomy: Term", "Taxonomy: Term Node Count Term Node Count "

And finally created a "Block" display.

Hope I save someone else the trouble I had to go through.

busla’s picture

You can achive the same thing with Panels and PM, without using HS.

Make sure that the following modules are enabled:
Views, Panels, Views content panes, Page Manager

Views
Add new Taxonomy view
Add a new Content pane display
Add field -> Term: name
Add contextual filter -> Taxonomy term: Parent term
Click Argument input and select From context and Required context as Term ID

Page Manager/Panels
Enable the Taxonomy term template
Add a new variant
Context -> Relationships -> Add the Term parent relationship
Select a layout
Pick a pane and Add content from the cogwheel
Click View Panes and select the View pane you created earlier.
Select Term parent as a context argument.

That was fun :-)

Edit:
It´s also possible to skip this whole tutorial and just go to the Taxonomy panel page and add the "Term being viewed" content. It allows you to select parents, siblings or children.

fernly’s picture

Technically it's not Views only. You'll need a small helper module: https://drupal.org/project/views_arg_parent_term
This allows you to load the parent term of the current term being viewed as a contextual filter.

You will need to make one more change to this helper module:
https://drupal.org/node/2183317

After getting this parent term as a contextual filter it's easy to load the childs (= siblings of current term) in the view.

---
Vaerenbergh.com - A Drupal developer's web page

Leagnus’s picture

it works! Thank You.
One todo is to hide current term name from resulting lists of terms.

studio-days’s picture

Here's my solution

Leagnus’s picture

it's nice solution if there's no need to preserve old urls/aliases for search – Google, Yahoo – systems.

justaman’s picture

for this type of issue, I stop and ask myself: what entity am I trying to print?

For this, one common mistake is to try to paint the parent. When you do the contextual filtering, it will also filter out the parent's siblings, leaving you with the displaying element only.

Another common error, is to forget to create a row for each element. If we make this mistake, every element will display several times. (cardinal join)

So:

I am trying to print the node I am seeing.

Create a contextual filter by nid, default value = node id from URL.
Create a relationship with the parent.
Add the siblings field (use parent relationship), on "Multiple field settings", uncheck "Display all values in the same row" .
Add the sorting (use parent relationship), parent delta. for the siblings field.

pancho2jr’s picture

Hey I seem to find a way.

I create a view with relation of parent term , and also add a contetual filter containing this relation .

In my case i provide a Raw value from the URL in the contextual filter and make it point to the parent . that works for me so now in .

Example: /vocab_name/taxonomy_parent/taxonomy_child
it shows me all the childs from "taxonomy_parent" .

Hope this helps someone