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

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.

  $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;

valuable tool for community building

wbmangy - November 29, 2007 - 02:44

Thanks for a great snippet! Works like a charm, and makes a nice addition to the tools available to a website's members for managing their online reputations - a significant concern on community-oriented sites. Useful to know what else the author has done as you read what they've written.

Note if you're a newbie like me: 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!)

display user specific images on a user's cck "gallery" page

lsabug - December 27, 2007 - 18:45

Use the following in the argument handling code 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):

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.