1

Hello i have been trying for many a moon to create this View and i cant go on any longer its destrying my life (honest)

I want to show Related Terms (not content) on my taxonomy/term/* page. Example.

White Setter and Black Setter are both in a dogs vocabulary. I have 'related' them via the taxonomy/term/*/edit-term page.

I want to create a block view that will show Black Setter on the White Setter page and vica versa. I have tried every relationship and every argument with no success at all. Does anyone know if this is possible to make?

Relationships Taxonomy: Related terms Arguments Taxonomy: Term ID

Thanks

Before i post i see that i have asked ths on other peoples posts (and one of mine) they where never resolved. People keep talking about adding nodes in the view but i was wanting to use a term View.

2
  • Which version of Drupal are you using ? 6 or 7 ?
    – Anil Sagar
    Commented Oct 29, 2012 at 4:18
  • Sorry Anil Drupal 6.
    – Reg Gordon
    Commented Oct 29, 2012 at 14:18

2 Answers 2

1
+50

It's not really hard:

  1. Create a new taxonomy view.
  2. Add an argument: Taxonomy: Term ID. If argument is not present, provide a default argument: Taxonomy Term ID from URL. Check the Load default argument from term page checkbox.
  3. Add a relationship: Taxonomy: Related terms.
  4. Finally, add a field: Taxonomy: Term. Use the Related term relationship, and check the Link this field to its taxonomy term page option.
  5. Don't forget to create the block display.

Here's a view export: https://gist.github.com/4016927

6
  • Core stores term relationships as "A is related to B" and the Views handler is not wise enought to check that "B is related to A". Therefore, right now, this is broken in Views 6.x-2.x and 6.x-3.x (didn't check 7.x-3.x). Commented Nov 5, 2012 at 12:52
  • See drupal.org/node/1825688 Commented Nov 5, 2012 at 15:54
  • thanks barraponto i missed this. yes that was me on drupal.org. i will go look more at this as the view will interest me. Loads to get on with now this is solved but i will return
    – Reg Gordon
    Commented Nov 5, 2012 at 17:14
  • barraponto's View does seem to work ok and as i had hoped (including on the node) I need to edit each term and resave them for the 2 way relationship to come into place. Sorry folks im just up and not thinking straight. Sorry Anoop but using a view like barra suggested seems a better way for me to go. thanks for your input though
    – Reg Gordon
    Commented Nov 5, 2012 at 17:36
  • @RegGordon unfortunately, saving the related term will break it on the other related term. So right now, what you're left with is custom code. Commented Nov 5, 2012 at 18:35
5

As your requirement is to create a block that will show Black Setter on the White Setter page and vica versa, there is another simple way to achieve this. The function taxonomy_get_related() will do this.

Create a block with input format as php and use above function to print related terms by passing current page term id. Then assign the block to particular region. The following snippet will works,

for eg:

 <?php
    $termid = arg(2);
    $terms = taxonomy_get_related($termid, $key = 'tid');
    //print_r($terms);
    foreach($terms as $term){

       $link = url('taxonomy/term/'.$term->tid);
       echo '<a href="'.$link.'">'.$term->name.'</a>';
     }
  ?>
6
  • ah brilliant Anoop that seems to be the way to go. It is printing the term fine as hoped but it isnt linking the term to the term page. Would there be a way to sort this? thanks very much.
    – Reg Gordon
    Commented Nov 4, 2012 at 21:41
  • i edited answer please check now Commented Nov 5, 2012 at 4:26
  • lovely works a dream Anoop. Much appreciated. This really helps me and im sure it will realy help others too.
    – Reg Gordon
    Commented Nov 5, 2012 at 17:11
  • is there any way that the output could also be displayed on a node to emulate the " Load default argument from node page, thats good for related taxonomy blocks" way? I was hoping to use this as a menu system. thanks
    – Reg Gordon
    Commented Nov 5, 2012 at 17:20
  • As I explained in my answer's comments, Views handling of related terms is broken, so you're left with custom code solutions. That said, avoid leaving snippets of PHP in your database as debugging or mantaining it is way harder than actual code. Commented Nov 5, 2012 at 18:37

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.