Posted by iancawthorne on April 3, 2007 at 3:39pm
Is it possible to list taxonomy terms using views or anything similar?
Example: I have a gallery as the vocab name, which has "landscape, seascape, portrait" etc as the terms.
would like to list these names with the first node image as a teaser.
Comments
Here you go
No need for Views. Just create a php page:
<?php$vid = 1; /* <---- put correct vocabulary ID here */
$terms = taxonomy_get_tree($vid); /* need code from below to handle nesting */
print "<ul>";
foreach ( $terms as $term ) {
$count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d ", $term->tid));
if ($count) { /* don't show terms with 0 count */
print "<li>".$term->name." (".$count.")</li>";
}
} /* end foreach */
print "</ul>";
?>
And it's clear you didn't search the forums very hard before asking this. I've posted this at least 3 times in the last two weeks.
Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in Your Database
NancyDru
Thanks... nearly
Thanks, I did have a very similar php code, but was hoping it might be able to be configured with views rather than creating a php page.
This code lists the terms, which is close, but I'd like to pull the teaser of the first node in that term (an image thumbnail in this case)
An example would be, I have a term type of 'landscapes' in my vocab type 'gallery'.
I have 4 nodes attatched to this term type, the first being 'Scottish Mountain Range' with a thumbnail.
I'd like to pull through that thumbnail to go next to the name 'Landscapes' in that list to make it more visual.
Hydrant Ltd
www.hydrant.co.uk
Allegedly
This is supposed to be do-able with Views, I think. I prefer this method because it's faster, but many people prefer to rely on Merlin's code.
Yours is an interesting concept, however. It might give the "icon-ized" menu look that a lot of people have asked for. This is something that I might consider for a module I'm working on.
Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in Your Database
NancyDru
language i18n
Hello,
This code works fine for the term name in the term_data table, but can it also read the translated terms?
Hope someone knows a solution.
TIA,
Fossie
nobody has a clue? Fossie
nobody has a clue?
Fossie
nobody has a clue? Fossie
nobody has a clue?
Fossie
fossie - are you trying to
fossie - are you trying to do something similar to what I have on the right side of my page:
http://the.singularitynetwork.org
?
i need this...
how did you do it?
also can it limit the number of terms listed?
The code I posted above
The code I posted above can just as easily be put into a block, which is what it looks like he did.
I suppose you could limit the number of terms, but it is in alphabetical order, so you won't see the Z entries.
Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database
NancyDru
subscribing
subscribing
can this code be modified so
can this code be modified so it will recognize parent and child categories?
Here is with linked rows.
It will be show links to terms of taxonomy:
<?phpfor ($i=1;$i<=200;$i++) {
$vid = $i; /* <---- all (now max. 200) vocabulary ID here */
$terms = taxonomy_get_tree($vid); /* need code from below to handle nesting */
print "<ul>";
foreach ( $terms as $term ) {
$count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d ", $term->tid));
if ($count) { /* don't show terms with 0 count */
print '<li><a href="?q=taxonomy/term/'.$i.'">'.$term->name.' ('.$count.')</a></li>';
}
} /* end foreach */
print "</ul>";
}
?>
I hope it will be usefull. :)
Greetings all.Now use this
Greetings all.
Now use this code in the block,
<? php$ vid = 1; / * <---- put correct vocabulary ID here * /
$ terms = taxonomy_get_tree ($ vid);
foreach ($ terms as $ term) (
$ tcount = taxonomy_term_count_nodes ($ term-> tid);
$ children_terms = taxonomy_get_children ($ term-> tid);
if ($ term-> depth == 0) (
print l ("-".$ term-> name, 'taxonomy / term /'
. $ term-> tid, array ( 'title' => $ tcount. "posts in"
. $ term-> name));
print ( "<br>");
)
)
?>
But I do not know how to do filtering by language, to render all the terms, although they mutually serve each other translations
-Africa
-Asia
-Australia and Oceania
-Europe
-North America
-South America
-Австралия и Океания
-Азия
-Африка
-Европа
-Северная Америка
-Южная Америка
How display terms only the language of the desired vocabulary taxonomy? (Using - drupal 6*, i18n )
Almost what I was looking
Almost what I was looking for, this code displays the the term id incorrectly as it's set to display the vid so the terms don't link correctly, for anyone having the same problem I used following:
print '
';
in place of
print '
';
-
I suggest using this tutorial instead:
http://drupal.org/node/770782
----
http://picxelplay.com
"After I'm gone, your earth will be free to live out its miserable span of existence, as one of my satellites, and that's how its going to be."
Drupal 7
Thanks for posting this great code.
This is code for Drupal 7 that worked fo me.
<?php
$vid = 2; /* <---- put correct vocabulary ID here */
$terms = taxonomy_get_tree($vid); /* need code from below to handle nesting */
dsm($terms);
echo "<ul>";
foreach ( $terms as $term ) {
$count = db_query("SELECT COUNT(nid) FROM {taxonomy_index} WHERE tid = :tid ", array(':tid' => $term->tid))->fetchField();
if ($count) { /* don't show terms with 0 count */
print "<li>".$term->name." (".$count.")</li>";
}
}
echo "</ul>";
?>
Pro Info Design