I'd also like to request that next to the "Embed Children view" box, that there be a tickbox that says "Include siblings and parent". I'm attempting to create articles in a series, and it'd be kinda useful if I could have a way of just clicking something and ticking a box to get an index to those articles at the end of the article.

Comments

rhache’s picture

Version: 5.x-1.x-dev » 5.x-1.0

I have to agree with this sentiment. Sometimes it's the sibling relationship that matters, and this would make it easier if the module had this feature included.

Otherwise great module.

Thanks,
Rene

meecect’s picture

I made a view to do this. It's a block view, but you can tailor it however you'd like...as a attachment, for example.

Note, it's difficult to test the view from the views ui due to the way that it works. Essentially, it uses the 'default argument' feature to get an argument if none is provided. It uses this to automatically get the parent node id in the absence of an argument. So it probably wont work on the view UI page, but will when you view the block or attachment for an actual node.

View export:

$view = new view;
$view->name = 'nodehierarchy_sibling_list';
$view->description = 'Display a node\'s siblings as a list';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$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('fields', array(
  'title' => 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,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
));
$handler->override_option('sorts', array(
  'order_by' => array(
    'id' => 'order_by',
    'table' => 'nodehierarchy',
    'field' => 'order_by',
    'order' => 'ASC',
  ),
));
$handler->override_option('arguments', array(
  'parent' => array(
    'default_action' => 'not found',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'php',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'parent',
    'table' => 'nodehierarchy',
    'field' => 'parent',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
      '3' => 0,
      '5' => 0,
      '7' => 0,
      '6' => 0,
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '18',
    'default_argument_php' => '$node = node_load(arg(1));
if ($node) {
  return $node->parent;
} else return;',
    'validate_argument_node_type' => array(
      'webform' => 0,
      'book' => 0,
      'page' => 0,
      'story' => 0,
      'faq' => 0,
      'weblinks' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '1' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_php' => '',
  ),
));
$handler->override_option('filters', array(
  'status' => array(
    'id' => 'status',
    'table' => 'node',
    'field' => 'status',
    'operator' => '=',
    'value' => 1,
    'group' => 0,
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'expose_button' => array(
      'button' => 'Expose',
    ),
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('style_plugin', 'list');
$handler->override_option('style_options', array(
  'type' => 'ul',
));
$handler->override_option('row_options', array(
  'teaser' => 1,
));
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('arguments', array(
  'parent' => array(
    'default_action' => 'default',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'php',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'parent',
    'table' => 'nodehierarchy',
    'field' => 'parent',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
      '3' => 0,
      '5' => 0,
      '7' => 0,
      '6' => 0,
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => 'test',
    'default_argument_php' => 'if (arg(0) == \'node\' && is_numeric(arg(1))) {
  $node = node_load(arg(1));
  return $node->parent;
} else {
  return FALSE;
}',
    'validate_argument_node_type' => array(
      'webform' => 0,
      'book' => 0,
      'page' => 0,
      'story' => 0,
      'faq' => 0,
      'weblinks' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '1' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_php' => '',
    'override' => array(
      'button' => 'Use default',
    ),
  ),
));
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);
Dracolyte’s picture

Version: 5.x-1.0 » 6.x-1.3

Thanks for the code. I'm using it in D6.13 and it works great.

taote’s picture

@meecect, I´m trying to get a block with next or previous node. This view gives you all the siblings. Do you know how to get only the next or the previous according to the order in the node hierarchy? Thanks

taarten’s picture

Wow thanks dude. It works fine!

grasmash’s picture

I've used this to get a list of siblings, but it doesn't list the parent. Is that possible?

boran’s picture

To produce a list of the parent, siblings and children (i.e. all "related nodes" in the node-custom.tpl, I do:

         if ($node->parent > 0) {
           $parent = node_load($node->parent);
           print l($parent->title, 'node/' . $parent->nid);
...
         // children then siblings
         print views_embed_view('related_nodes_list', 'block_2', $node->nid);
         if ($node->parent > 0) {
           print views_embed_view('related_nodes_list', 'block_2', $parent->nid);
         }

Related_node_list is a view cloned form nh_children view with the layout adapted to my needs.
Note that there is one disadvantage here: the siblings list also includes the current node, which may confuse users somewhat.