Show more nodes in a block by the author of the current node

Last modified: March 14, 2009 - 14:08

If a node of 'mytype' type is displayed then this code will display more 'mytype' nodes in a block (why are people posting recipes in the snippets section? They are hard to follow and error prone. This can be imported directly into views). Change mytype to your type whatever it is.

<?php
  $view = new stdClass();
  $view->name = 'other_nodes_by_the_same_owner';
  $view->description = '';
  $view->access = array (
  0 => '1',
  1 => '2',
);
  $view->view_args_php = 'if (arg(0) == \'node\' && is_numeric(arg(1)) && !arg(2) && ($node = node_load(arg(1))) && $node->type == \'mytype\') {
  return array($node->uid);
}
';
  $view->page = FALSE;
  $view->page_title = '';
  $view->page_header = '';
  $view->page_header_format = '1';
  $view->page_footer = '';
  $view->page_footer_format = '1';
  $view->page_empty = '';
  $view->page_empty_format = '1';
  $view->page_type = 'node';
  $view->url = '';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '3';
  $view->block = TRUE;
  $view->block_title = 'Other nodes by the same user';
  $view->block_header = '';
  $view->block_header_format = '1';
  $view->block_footer = '';
  $view->block_footer_format = '1';
  $view->block_empty = '';
  $view->block_empty_format = '1';
  $view->block_type = 'list';
  $view->nodes_per_block = '500';
  $view->block_more = TRUE;
  $view->block_use_page_header = FALSE;
  $view->block_use_page_footer = FALSE;
  $view->block_use_page_empty = FALSE;
  $view->sort = array (
  );
  $view->argument = array (
    array (
      'type' => 'uid',
      'argdefault' => '1',
      'title' => '',
      'options' => '',
      'wildcard' => '',
      'wildcard_substitution' => '',
    ),
  );
  $view->field = array (
    array (
      'tablename' => 'node',
      'field' => 'title',
      'label' => '',
      'handler' => 'views_handler_field_nodelink',
      'options' => 'link',
    ),
  );
  $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'type',
      'operator' => 'OR',
      'options' => '',
      'value' => array (
  0 => 'mytype',
),
    ),
    array (
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(node);
  $views[$view->name] = $view;
?php>

Note: wbmangy reminds us: After importing and saving this View snippet, make sure you enable the corresponding block on the Administer >> Sitebuilding >> Blocks page. (Nothing will show up until you do!)

For a view that will output user images/content on user created node (ex. to display user specific images on a user's cck gallery/page), lsabug suggests using the following in the argument handling code :
<?php
if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2) && ($node = node_load(arg(1))) && $node->type == 'usr_gallery') {
  return array(
$node->uid);
}
?>

Change 'usr_gallery' to the content type where you want it to display.

 
 

Drupal is a registered trademark of Dries Buytaert.