Hi,

I'm trying to create a block on every node page that lists the related terms to the category the node belongs to.

I have this so far:

$view = new view;
$view->name = 'related_terms';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'term_data';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
  'tid2' => array(
    'label' => 'Related term',
    'required' => 1,
    'id' => 'tid2',
    'table' => 'term_relation',
    'field' => 'tid2',
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'name' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_taxonomy' => 1,
    'exclude' => 0,
    'id' => 'name',
    'table' => 'term_data',
    'field' => 'name',
    'relationship' => 'tid2',
  ),
));
$handler->override_option('sorts', array(
  'name' => array(
    'order' => 'ASC',
    'id' => 'name',
    'table' => 'term_data',
    'field' => 'name',
    'relationship' => 'tid2',
  ),
));
$handler->override_option('filters', array(
  'vid' => array(
    'operator' => 'in',
    'value' => array(
      '1' => '1',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'vid',
    'table' => 'term_data',
    'field' => 'vid',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('items_per_page', 0);
$handler->override_option('style_options', array(
  'grouping' => '',
));
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);

This does list related terms but it doesn't list the related terms of every node. I know I need to add an argument but I'm not sure what the argument should be?

Many thanks.

Comments

littlemisssunshine’s picture

Sorry I meant to say the view doesn't list the related terms of the category each node belongs to.

littlemisssunshine’s picture

Does anybody have any ideas?

esmerel’s picture

Status: Active » Fixed

You might want to look at views_attach - it might be more of what you're looking for; blocks don't take arguments as easily as other methods. You can also maybe try using terms by establishing their relationship to the nid from url?

littlemisssunshine’s picture

What's views_attach? Sorry to seem clueless, it's something I've never used before.

dawehner’s picture

littlemisssunshine’s picture

Thank you very much.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.