How to display *only* the terms and the sub-terms of a term?

Venkat-Rk - October 16, 2005 - 13:51

This phpsnippet (http://drupal.org/node/23415#comment-60089) shows a nice way to display the terms of a particular vocabulary.

Could someone please help with code for the following?

1.) How can I show *just* a list of the vocabulary's terms- that is, without the count, last updated and the 'no content' info
2.) Similarly show *just* the sub-terms of a term?

Thanks in advance

Just list voculary terms

nevets - October 16, 2005 - 15:00

This snippet will just show the term names (linked to page list content with term) for a vocabulary

<?php
$vocabulary_id
= 1;
$result = db_query("SELECT d.tid, d.name FROM {term_data} d WHERE d.vid = $vocabulary_id GROUP BY d.tid, d.name ORDER BY d.name");
$items = array();
while (
$category = db_fetch_object($result)) {
$items[] = l($category->name, 'taxonomy/term/'. $category->tid);
}
print
theme('item_list', $items);
?>

add (# of nodes)?

nisguy - March 6, 2007 - 22:10

Greetings,
I'm trying to setup a list of sub-terms within a parent term and show the number# of nodes contained within (parentheses). For example, say my vocabulary is 'Food' and I have a term of 'Fruit', which has sub-terms called 'apples', 'oranges', and 'bananas'.

I want my list to appear like this if 'apples' had 3 nodes, ...etc:

All Fruit

The snippet above is great, I just need to add the (#) feature to the first snippet. Has anyone done this or can help?

List just the sub terms of a taxonomy term

nevets - October 16, 2005 - 15:05

This script will just show the sub-terms of a term (specified by setting $tid).

$tid = 6;
$items = array();
$children = taxonomy_get_children($tid);
foreach ( $children as $child ) {
$items[] = l($child->name, 'taxonomy/term/'. $child->tid);
}
print theme('item_list', $items);

Thanks, nevets. As always,

Venkat-Rk - October 17, 2005 - 06:52

Thanks, nevets. As always, you are kind to share these code snippets on the forums. They work great. I will find some time to add these to the handbook.

By the way, I had to add <?php> and ?> at the beginning and end of the above code to make it work.

Hi there... where i should

takien - December 5, 2007 - 20:10

Hi there...
where i should paste that code in .. ?
i'm using drupal 5.3
help please..

Either a custom block or node

nevets - December 5, 2007 - 20:38

You can either place the code in a custom block or in a node, in either case you will need the <?php and ?>tags around the code as mentioned above.

Hi, How can you show the

Summit - February 3, 2008 - 23:47

Hi,

How can you show the nodes in the list (title-body) instead of count of nodes?
Please assist,
thanks in advance,
greetings, Martijn

Something like the following

jimbop - February 4, 2008 - 00:43

Something like the following should work:

If using CCK... Where $options is an array of content types as defined in the cck table (i.e. for content type 'notice' this would be 'content_type_notice'):

<?php
foreach ($options as $type => $link) {
 
$result = db_query("
    SELECT
      node.title
    FROM node RIGHT JOIN $type USING (nid)"
 
);
  while (
$result_row = db_fetch_object($result)) {
    print
$result_row->title.'<br />'; //or whatever output you want
 
}
}
?>

Mind you, you're probably better off using the views module for this. Create a view there and call it manually as described in http://drupal.org/node/48816.

 
 

Drupal is a registered trademark of Dries Buytaert.