3

How can I take a "Content Type" with a "Taxonomy Term" field... and use views to generate a list of content with that term via URL?

I have a content type that has the basics (Title, Body) as well as Taxonomy Term for a Vocabulary & Weight. I want the user to be able to type:

http://myip.org/portals/safety

This would theoretically generate

  1. HTML list of pages
  2. "Menu" to be use in a block with a list of safety (or whatever) pages.

I can't seem to figure out where to get the taxonomy/term to work as variables in the View.

Views has the "Taxonomy Term" default view with

taxonomy/term/%
taxonomy/term/%/feed

I'd like to remove the /%,/%/feed and auto-magically make a taxonomy/term page/menu.

1 Answer 1

3

The key to views is to use the filter function to get the correct node relations out in the way you want. I had the same problem where I wanted a node of content type "application" with a taxonomy of "approved", "pending", and "denied". The view should get a with a filter of node: type = "applications", based on my example. That will find the right content. I added a base url of applications for the page view. The arguments section is where the taxonomy can be used to filter based on URL.

portals/safety node type = safety

portals/safety/one node type = safety taxonomy: term = one

portals/safety/two node type = safety taxonomy: term = two

It might be easier if I just export the view and see if it helps point the way along.

$view = new view;
$view->name = 'Applications';
$view->description = 'List of all applications';
$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', 'Application List', 'default');
$handler->override_option('fields', array(
  'title' => array(
    'label' => 'Application',
    '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_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Override',
    ),
  ),
  'name' => array(
    'id' => 'name',
    'table' => 'term_data',
    'field' => 'name',
  ),
));
$handler->override_option('arguments', array(
  'name' => array(
    'default_action' => 'ignore',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '%1 Status Application',
    'breadcrumb' => 'Applications',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'glossary' => 0,
    'limit' => '0',
    'case' => 'none',
    'path_case' => 'none',
    'transform_dash' => 0,
    'add_table' => 0,
    'require_value' => 0,
    'id' => 'name',
    'table' => 'term_data',
    'field' => 'name',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
      '3' => 0,
      '4' => 0,
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_fixed' => '',
    'default_argument_user' => 0,
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'blog' => 0,
      'poll' => 0,
      'faq' => 0,
      'forum' => 0,
      'application' => 0,
      'page' => 0,
      'story' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '1' => 0,
      '2' => 0,
      '3' => 0,
      '4' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_php' => '',
  ),
));
$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(
      'application' => 'application',
    ),
    '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' => 'time',
  'results_lifespan' => '3600',
  'output_lifespan' => '3600',
));
$handler->override_option('title', 'Applications');
$handler->override_option('style_plugin', 'list');
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'applications');
$handler->override_option('menu', array(
  'type' => 'tab',
  'title' => 'Applications',
  'description' => 'Applications',
  'weight' => '0',
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', 'Applications');
$handler->override_option('block_caching', -1);
4
  • I've adjusted this to my "Portals"... and in the test area, when using "safety" contextual it works. The three pages I have as safety pages show up in a list... but when I go to myip.org/portals/safety it just shows a blank page.
    – WernerCD
    Commented Apr 27, 2011 at 15:54
  • Not sure what I changed... but i got it working! vonderball... follow-up question coming shortly.
    – WernerCD
    Commented Apr 27, 2011 at 16:12
  • The issue I have atm... is the page version works, but it doesn't work as a block.
    – WernerCD
    Commented May 3, 2011 at 18:27
  • It wouldn't work in blocks because contextual filters rely on the page URL.
    – beth
    Commented Jun 11, 2012 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.