I am in desperate need of some clarification here. I have galleries that i want to display on specific nodes that have the same taxonomy term. The tid is not passed through the url when I go to a particular node of my node-type. I have looked at the documentation and seen code on how to add a php snippet but nothing shows in my view, only in the preview on the view building page. I am calling the view programatically in my custom node template.

$view = views_get_view('image_gallery2');
print $view->preview('default', $args);

Here is my view currently.

$view = new view;
$view->name = 'image_gallery2';
$view->description = 'The safani gallery of image nodes from Image gallery module.';
$view->tag = 'image_gallery2';
$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(
'image_image' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
),
'link_to_node' => 1,
'image_derivative' => 'thumbnail',
'exclude' => 0,
'id' => 'image_image',
'table' => 'node',
'field' => 'image_image',
'relationship' => 'none',
),
'title' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
),
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
));
$handler->override_option('sorts', array(
'title' => array(
'id' => 'title',
'table' => 'node',
'field' => 'title',
),
'changed' => array(
'order' => 'DESC',
'granularity' => 'second',
'id' => 'changed',
'table' => 'node',
'field' => 'changed',
'relationship' => 'none',
),
));
$handler->override_option('arguments', array(
'null' => array(
'default_action' => 'default',
'style_plugin' => 'default_summary',
'style_options' => array(),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => '',
'breadcrumb' => '',
'default_argument_type' => 'node',
'default_argument' => '',
'validate_type' => 'none',
'validate_fail' => 'not found',
'must_not_be' => 0,
'id' => 'null',
'table' => 'views',
'field' => 'null',
'validate_user_argument_type' => 'uid',
'validate_user_roles' => array(
'2' => 0,
'3' => 0,
),
'relationship' => 'none',
'default_options_div_prefix' => '',
'default_argument_fixed' => '',
'default_argument_user' => 0,
'default_argument_image_size' => '_original',
'default_argument_php' => '',
'validate_argument_node_type' => array(
'exhibit' => 0,
'feed_fast' => 0,
'feed' => 0,
'feed_item' => 0,
'image' => 0,
'panel' => 0,
'comment' => 0,
'page' => 0,
'review' => 0,
'stadium' => 0,
'story' => 0,
),
'validate_argument_node_access' => 0,
'validate_argument_nid_type' => 'nid',
'validate_argument_vocabulary' => array(
'4' => 0,
'1' => 0,
),
'validate_argument_type' => 'tid',
'validate_argument_transform' => 0,
'validate_user_restrict_roles' => 0,
'image_size' => array(
'_original' => '_original',
'thumbnail' => 'thumbnail',
'preview' => 'preview',
),
'validate_argument_php' => '',
),
'tid' => 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' => 'node',
'validate_fail' => 'empty',
'break_phrase' => 0,
'add_table' => 0,
'require_value' => 0,
'reduce_duplicates' => 0,
'set_breadcrumb' => 1,
'id' => 'tid',
'table' => 'term_node',
'field' => 'tid',
'relationship' => 'none',
'default_options_div_prefix' => '',
'default_argument_user' => 0,
'default_argument_fixed' => '8',
'default_argument_php' => 'if (arg(0) == \'node\' && is_numeric(arg(1))) {
$node=node_load(arg(1));
$term = taxonomy_node_get_terms_by_vocabulary($node->nid, 4);
$args[0] = key($term);
}
return $args[0];',
'validate_argument_node_type' => array(
'stadium' => 'stadium',
'exhibit' => 0,
'feed_fast' => 0,
'feed' => 0,
'feed_item' => 0,
'image' => 0,
'panel' => 0,
'comment' => 0,
'page' => 0,
'review' => 0,
'story' => 0,
),
'validate_argument_node_access' => 0,
'validate_argument_nid_type' => 'nid',
'validate_argument_vocabulary' => array(
'4' => 4,
'1' => 0,
),
'validate_argument_type' => 'tid',
'user_argument_type' => 'uid',
'restrict_user_roles' => 0,
'user_roles' => array(),
'image_size' => array(
'_original' => '_original',
'thumbnail' => 'thumbnail',
'preview' => 'preview',
),
'validate_argument_php' => '',
'override' => array(
'button' => 'Override',
),
'validate_user_argument_type' => 'uid',
'validate_user_roles' => array(
'2' => 0,
'3' => 0,
),
'default_argument_image_size' => '_original',
'validate_argument_transform' => 0,
'validate_user_restrict_roles' => 0,
),
));
$handler->override_option('filters', array(
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'relationship' => 'none',
),
'type' => array(
'operator' => 'in',
'value' => array(
'image' => 'image',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('title', 'Image galleries');
$handler->override_option('empty', 'There are no images in this gallery.');
$handler->override_option('empty_format', '1');
$handler->override_option('items_per_page', 12);
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'image_gallery');
$handler->override_option('style_options', array(
'grouping' => '',
'type' => 'ul',
));
$handler = $view->new_display('image_gallery', 'Gallery page', 'image_gallery_1');
$handler->override_option('path', 'image');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));

Help would be much appreciated. I want to go to a node and see the image gallery that has the same taxonomy term as that node.

Comments

safani’s picture

safani’s picture

Issue tags: +arguments
safani’s picture

Priority: Normal » Major

This is so frustrating. I understand arguments completely as far as passing through urls. Without a url argument I am clueless...where is the documentation for this I would at least like to be pointed in the right direction. I have been searching all day and nothing specifically matches my issue, yet I know drupal is capable of what I desire.

Someone please , Anyone?

JEMBALINA’s picture

Try executing this before your execute the view in your node template:
$view->set_arguments(array('argument1', 'argument2'));

I think it should look something like this (assuming $args in an array with 2 elements):

$view = views_get_view('image_gallery2');
$view->set_display('default');
$view->set_arguments(array($args[0], $args[1]));
$view->execute();
dawehner’s picture

Better use view->preview instead of set_display and set_arguments.
It's much safer/easier to use this function.

Even more easier you could use views_embed_view

views_embed_view('viewname', 'display_id', $arg1, $arg2);
iamjon’s picture

Status: Active » Closed (fixed)

Closing based on comments #5 and #4