Hi, I am using Views2 and Im working now on showing the terms I created using Taxonomy module of Drupal. I tried all the fields available for taxonomy category but can't produce the view I want.. How can I produce this kind of result?

Blog Topics // this is the header of the view

    Animals (2) // 2 is the number of blogs on that particular taxonomy term
    Human (10) //same as above; 10 is the number of posts
    Insects (3) //*same as above

I hope someone have done this... Please share your knowledge to me.. Thanks!

Comments

dawehner’s picture

Status: Active » Fixed

This view does exactly what you want

$view = new view;
$view->name = 'blog_posts';
$view->description = '';
$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' => 'Title',
    '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('arguments', array(
  'tid' => array(
    'default_action' => 'summary asc',
    'style_plugin' => 'default_summary',
    'style_options' => array(
      'count' => 1,
      'override' => 0,
      'items_per_page' => '25',
    ),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'add_table' => 0,
    'require_value' => 0,
    'reduce_duplicates' => 0,
    'set_breadcrumb' => 0,
    'id' => 'tid',
    'table' => 'term_node',
    'field' => 'tid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
      '3' => 0,
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'album' => 0,
      'kuenstler' => 0,
      'story' => 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('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('title', 'Blog Posts');

Perhaps you have to add some filters.

dhon’s picture

Status: Fixed » Active

Thanks for the fast reply..I really appreciate your work.. I just want to know how will I change the link path of the category.. I looked into it and it just linked to my homepage...how can I link it to the page of the particular category???

like this one:

Blog Posts //title
Animal (2) //when I click the Animal link, it will go to the page of that term. e.g: http://mysitehome.com/category/vocabulary/animal
Human (10) //*same as above//

Thanks in advance! I know it will be easy for you..:)

dhon’s picture

Any solutions for this? Please I really need it thanks!

dawehner’s picture

Status: Active » Fixed

You can use hook_preprocess_views_view_summary and alter $vars['rows'][$id]->url

This is doable in your template.php

dhon’s picture

Status: Fixed » Active

I can't understand what you instructed to me..

Do I need to create function hook_preprocess_views_view_summary on my theme's template.php then put $vars['rows'][$id]->url on its body code? I tried this and comes up to an error.. Please elaborate the solution more. Thanks!

dawehner’s picture

Checkout template_preprocess_views_view_summary in views code. There you see how the links are generated. With your own hook_preprocess_views_view_summary you can override the url .

Therefore you have to understand php.

dhon’s picture

still can't get your point.. i know php but I dont understand where is the views code located? is it on the views folder? and another thing the url I want should be still dynamic depending what category is clicked.. Can it be done? please i really need this one badly.. many thanks to you!

dhon’s picture

still looking for a solution to this...thanks!

dhon’s picture

~bump!

dawehner’s picture

Status: Active » Fixed
function template_preprocess_views_view_summary(&$vars) {
  $view     = $vars['view'];
  $argument = $view->argument[$view->build_info['summary_level']];

  $url_options = array();

  if (!empty($view->exposed_raw_input)) {
    $url_options['query'] = $view->exposed_raw_input;
  }
  foreach ($vars['rows'] as $id => $row) {
    $vars['rows'][$id]->link = $argument->summary_name($row);
    $args = $view->args;
    $args[$argument->position] = $argument->summary_argument($row);

    $vars['rows'][$id]->url = url($view->get_url($args), $url_options);
    $vars['rows'][$id]->count = intval($row->{$argument->count_alias});
  }
}

Copy this into your template.php
Rename the function. Check the view name and alter the url here. You have to know php to be able to do this.

dawehner’s picture

function template_preprocess_views_view_summary(&$vars) {
  $view     = $vars['view'];
  $argument = $view->argument[$view->build_info['summary_level']];

  $url_options = array();

  if (!empty($view->exposed_raw_input)) {
    $url_options['query'] = $view->exposed_raw_input;
  }
  foreach ($vars['rows'] as $id => $row) {
    $vars['rows'][$id]->link = $argument->summary_name($row);
    $args = $view->args;
    $args[$argument->position] = $argument->summary_argument($row);

    $vars['rows'][$id]->url = url($view->get_url($args), $url_options);
    $vars['rows'][$id]->count = intval($row->{$argument->count_alias});
  }
}

Copy this into your template.php
Rename the function. Check the view name and alter the url here. You have to know php to be able to do this.

dhon’s picture

Status: Fixed » Active

i still cant make it work...

i copied the code on the template.php on my theme's directory.
change the name of view to blog_posts...

can you give more elaborated instructions? please..

dawehner’s picture

blog_posts is the name of your theme?

Can you define the url, you want to link to? Then i will write down the code for you, which will save time for me.

dhon’s picture

blog_posts is the name of the views... my theme's name is sandium

the URL i want is the URL for the respective term. So if I have three terms they have their URLs respectively. I guess we can get a way to get the URL depending on the term id?

dawehner’s picture

So you need sandium_preprocess_views_view_summary

dhon’s picture

is that all I need to change on the code above???

dawehner’s picture

No you have to add code, not hacking existing ones. I need to change on the code above???

dhon’s picture

yes please...i really cant do it... thanks!

dawehner’s picture


function yourtheme_preprocess_views_view_summary(&$vars) {
  $view     = $vars['view'];
  if ($view->name != 'yourviewname') {
    return;
  }
  $argument = $view->argument[$view->build_info['summary_level']];

  $url_options = array();

  if (!empty($view->exposed_raw_input)) {
    $url_options['query'] = $view->exposed_raw_input;
  }
  foreach ($vars['rows'] as $id => $row) {
    dvm($row);
    $vars['rows'][$id]->link = $argument->summary_name($row);
    $args = $view->args;
    $args[$argument->position] = $argument->summary_argument($row);

    $vars['rows'][$id]->url = url($view->get_url($args), $url_options);
    $vars['rows'][$id]->count = intval($row->{$argument->count_alias});
  }
}

Paste this code into your template.php rename the function and install the devel modul. Then show us, what you get

dhon’s picture

Status: Active » Fixed

thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.