Hi there -
I'm a bit of a newbie, so maybe this is obvious, but I could not find the answer anywhere.

I would like to create a list of taxonomy terms that link to a path like /mycategory/nn where nn is a Taxonomy ID argument.

Why are there filters and arguments for TID but it's not available as a field?

Thanks!

Comments

dawehner’s picture

StatusFileSize
new25.3 KB

this is a hidden feature of views :)

here is the field taxonomy: term

see the screenshot for help, there is a rewrite output token [tid]

dawehner’s picture

Status: Active » Fixed

so this is fixed

merlinofchaos’s picture

Status: Fixed » Active

It's probably not actually completely fixed. Given the new rewriting functionality, we probably now have a real need to get true access to the TID.

squarecandy’s picture

StatusFileSize
new4.39 KB
new122.45 KB

Thanks for the screen shot dereine...
But I can't seem to replicate this in my view.

Attached are a screen shot of my "edit - field - Taxonomy: Term" and an export of my view.

Any clues for me?

Thanks!

squarecandy’s picture

Ok - I got [tid] to appear like in deriene's screenshot by adding Field - Taxonomy: All Terms above Taxonomy: Term.

But this does not accomplish what I'm looking for. When I use the [tid] token from All Terms it gives me a text output of all of the terms associated with the node - what I want is to get the Term ID number from the list I've created with Taxonomy: Term so I can make it into a link and pass it to the URL.

So I can go from this kind of page:
http://berkfilm.srv1.graymatterhost.com/productionguide/list/2

to this one:
http://berkfilm.srv1.graymatterhost.com/productionguide/sub/81
where the last URL segment is a Term ID argument

I checked out Taxonomy Menu to try and do all of this, but I couldn't get it to do exactly what I need, so I'm trying to do it with views myself.

alanburke’s picture

Subscribe.
Would be useful to have the tid for advanced themeing.

Eg - Output Tid as a field [restricted by vocabulary if necessary].
Exclude from Display.
Now re-use in a template file as a class to theme the row.

It can be done by loading the full node in the temapate file, but that isn't ideal.

Regards
Alan

squarecandy’s picture

I've also noticed that there are several threads about converting taxonomy terms with special characters to and back from the URL path, which there doesn't seem to be a good solution for... My solution was to try to use TID in the URL instead of the term name, but then realized that views provides no way of creating a link with a numeric term TID in the url.

Is there an example or guide somewhere for the best way to integrate taxonomy and views? This seems like a pretty common thing to want to do:

  • A taxonomy hierarchy of terms as a way of organizing content and avoiding creating duplicate content (a node can belong to more than one taxonomy category - a taxonomy category can have special characters in the name)
  • A view to list the content items in a certain category [linking to:]
  • A second view for the individual node with a breadcrumb indicating the category you got there from (not just a list of all categories that node exists in)

If someone has figured out an "ideal" way to do this and wants to share, I would be happy to help with documenting it...

Thanks!

Max_Headroom’s picture

This worked for me:
http://drupal.org/node/381346

mlncn’s picture

Our need was to get the term ID when limiting results to a specific vocabulary... which requires the "All terms" option.

There was no 'filter terms by vocabulary, provide term id' option -- when using taxonomy all terms, the only thing providing the filter by vocabulary option, it ONLY provides the term name (as link or plain).

This patch provides a third option, for TID. It attempts to keep the original variable profile (TRUE and FALSE) for linked term and plaintext term, so that it does not affect existing sites.

mlncn’s picture

Version: 6.x-2.5 » 6.x-2.6
Assigned: Unassigned » mlncn
Status: Active » Needs review

If it's possible to get this data without a patch, fantastic; or if this patch should be taking a very different approach, please put me in the right direction, but if this can just make life a little easier in the waning days of 2.x, I would hugely appreciate a commit.

dawehner’s picture

+++ modules/taxonomy/views_handler_field_term_node_tid.inc	2009-08-22 20:11:31.000000000 -0400
@@ -85,14 +90,16 @@ class views_handler_field_term_node_tid 
+        elseif ($this->options['link_to_taxonomy'] == TRUE) {

there is no == TRUE needed, but sure thats minor.
As far as i understand it, it shouldn't brake any existing taxonomy tid field, or?

I'm on crack. Are you, too?

shadowx’s picture

For squarecandy's purpose, maybe you could use "Taxonomy Redirect" module to accomplish your task. This module can rewrite typical "taxonomy/term/TERMID" path to new mapped path you want.

mlncn’s picture

Version: 6.x-2.6 » 6.x-2.x-dev

Still using this on production and all's well, as long as the patch is in effect. Also a person at the DrupalCon Taxonomy session had this exact same problem, no term IDs available as fields. If only all questions directed my way were answered by patches written a week prior...

This works and is needed, still happy to change the implementation if there's a better way. Anyone able to test if this applies as-is to Views HEAD? It probably does but i will check or re-roll before setting this to RTBC.

gausarts’s picture

Subscribing. Currently looking for a way to exclude term ID from URL, just like the node. Thanks

Update: Marking this related => http://drupal.org/node/576032 :)

SeanBannister’s picture

Just tested the patch and it certainly solved my problem.

Is there any reason that TID is listed as an option on "Taxonomy: All terms". It took me a while to find it as I was expecting it to be listed as a separate field called "Taxonomy: TID".

The reason I thought this is it seems very similar to "Node: Nid" and "Node: Title".

verot’s picture

Version: 6.x-2.x-dev » 6.x-2.7
StatusFileSize
new2.25 KB

Patch from poster #9, updated to work with 6.x-2.7

dagmar’s picture

Version: 6.x-2.7 » 6.x-2.x-dev
Assigned: mlncn » Unassigned
Status: Needs review » Needs work
+++ modules/taxonomy/views_handler_field_term_node_tid.inc	(working copy)
@@ -85,15 +90,19 @@
+        if ($this->options['link_to_taxonomy'] == 'tid') {
+          $this->items[$term->node_vid][$term->tid]['name'] = $term->tid;
+        } elseif ($this->options['link_to_taxonomy'] == TRUE) {
+          $this->items[$term->node_vid][$term->tid]['name'] = check_plain($term->name);
           $this->items[$term->node_vid][$term->tid]['make_link'] = TRUE;
-          $this->items[$term->node_vid][$term->tid]['path'] = taxonomy_term_path($term);
-        }
+          $this->items[$term->node_vid][$term->tid]['path'] = taxonomy_term_path($term);           
+        } else { // term only
+          $this->items[$term->node_vid][$term->tid]['name'] = check_plain($term->name);
+        }        

This code doesn't respect the http://drupal.org/coding-standards

VTM’s picture

Works OK for a single term assignment.

Assigning two or more terms, makes the [tid] field (of "all terms") display all terms taxonomy IDs.
This is fine for display but when I want to output this field as a link, all assigned term IDs are ONE link, and the address of the link contains all terms IDs separated by the separator.
This generate an SQL syntax error...

Is there a solution for this, as I use more than one term.

Many thanks.

Jerome F’s picture

Hi,

I rely on views customfield to do some php with my views fields.

I usually make use of the following code to display the available variables of my view :

<?php
print var_export($data, TRUE);
?>

It appears taxonomy all terms has no available array in $data ; why is that so and how and where can I get this variable ?

I found this related issue but that doesn't give me much hope to find out a solution.
http://drupal.org/node/371748

esmerel’s picture

Status: Needs work » Closed (won't fix)

No work done on patch in more than 3 months

petu’s picture

Status: Closed (won't fix) » Needs work

Still actual for views 6.x-3.0-alpha3.

dawehner’s picture

Status: Needs work » Closed (won't fix)

@petu

As long you don't want to continue the patch work this patch remains on won't fix.