Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Within my view, I'm using a contextual filter—with a default "summary output"—to filter my results by taxonomy term.

The problem is that the summary-result is grouped by a listing of taxonomy term-id's (including a node count) and not human readable term-id names.

  • 1 (21)
  • 2 (16)
  • etc.

Is it possible to change (or hook) the view output of the summary, by not listing its term-id's, but the term-id-name?

  • Term name A (21)
  • Term name B (16)

(It doesn't bother for me if the actual request URL stays the same.)

My goal is to create a more readable output-format of my taxonomy-term summary, which an end user can understand.

share|improve this question
I've found the same question being asked on How do I use Views argument to return taxonomy term names and not term ID's?, and an active discussion about it on Set the view title to term name when filter argument is term id. They deliver a patch, but without any success. – Stefan Looij Oct 5 '11 at 11:42

3 Answers

  1. Set your view to fields and expose the field that contains the associated taxonomy term.

  2. Set your contextual filter to filter for a taxonomy term and select to include a validator.

  3. Set the validator to taxonomy term and check the box for your vocabulary.

  4. Select the option for filter value type as ' Term name converted to Term ID.

  5. Save the filter and go to the preview box. If you enter the text name of your term, you should see the desired content.

If you are passing the information from the URl you may have to select the 'Transform dashes in URL to spaces in term name filter values' checkbox as well since the machine name uses dashes

share|improve this answer
This gets the job done perfectly. Thank you. – Lester Peabody Jan 19 '12 at 21:14

Copy the "views_view-summary.tpl.php" file your "modules/contrib/views/theme" folder. (You can make it view or block specific by adding a filename-suffix.)

Note: If you use this as a admin view-display, make sure you copy this file within the admin theme folder, not your default theme folder!

You don't need any changes in your display-settings. Just adjust your tpl-override to the following lines, and your Term-ID's are converted to readable Term-names:

<div class="item-list">
  <ul class="views-summary">
    <?php foreach ($rows as $id => $row): ?>
    <li>
      <a href="<?php print $row->url; ?>"<?php print !empty($row_classes[$id]) ? ' class="'. $row_classes[$id] .'"' : ''; ?>>
        <?php
        /* begin replacement */
        $term_object = taxonomy_term_load($row->link);
        print  $term_object->name; 
        /* end replacement*/
        ?>
      </a>
      <?php if (!empty($options['count'])): ?>
      &nbsp;(<?php print $row->count?>)
      <?php endif; ?>
    </li>
    <?php endforeach; ?>
  </ul>
</div>
share|improve this answer

There is an article on Drupal easy: Using display attachments to provide a consistent summary in Views 2.

share|improve this answer
With your example or for example based on a node-title as a contextual filter, it is working properly. But in my question the contextual filter is based on it's Taxonomy term. In this case the summary will display only the Term ID's and you are unable to show the more - readable - Term names. – Stefan Looij Oct 4 '11 at 8:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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