2

Drupal 7

I have a vocabulary with hierarchical terms countries and cities.

I have a view with context filter=cityA ( parent country A)

How I can display into a block all cities from country A ( siblings of cityA from vocabulary)?

Thanks

1 Answer 1

1

You can try using taxonomy_get_children($termid) to get children of term and then taxonomy_get_parents($termid) and again taxonomy_get_children() to get the siblings . The following is the code I used in such situation :

<?php

if (isset($page['#views_contextual_links_info']['views_ui']['view']->args[0])){
    $termid = $page['#views_contextual_links_info']['views_ui']['view']->args[0];
    $terms = taxonomy_get_children($termid);

    if (empty($terms)) {
        $parent = taxonomy_get_parents($termid);
        $terms = taxonomy_get_children(key($parent));
    }
}

if (isset($node->field_category['und'][0]['tid'])) {
    $termid =  $node->field_category['und'][0]['tid'];
    $terms = taxonomy_get_children($termid);
}

?>
5
  • Where specified vocabulary?
    – MariusM
    Commented Jun 21, 2012 at 14:07
  • we generalise the taxonomy terms in $terms and $termid . Commented Jun 21, 2012 at 18:55
  • Do not know why isset($page['#views_contextual_links_info']['views_ui']['view']->args[0])) return False in this page site.com/view/cityA
    – MariusM
    Commented Jun 22, 2012 at 11:08
  • Could you please paste the code you are using ? and which file you are using this code in ? Commented Jun 22, 2012 at 16:22
  • I used the code above, in a block. I have a view with 1 contextual filters(arguments) site.com/view/city
    – MariusM
    Commented Jun 25, 2012 at 10:17

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.