Is it possible to do the following

a) Get all taxonomy terms
b) Select a single term
c) Select all nodes belonging to this term and list them as a unordered list

repeat for the next taxonomy term and so on?

Comments

zach harkey’s picture

I'm pretty sure I know what you want and the answer is no. I like to think of it as the elephant in the room that is Drupal.

-zach
--
harkey design

: z

mokargas’s picture

There's no way to get a list of nodes by taxonomy term?

quickshare’s picture

Here is just some pointers to PHP functions that might do the job for you.

If you do not know the vocabulary id you would first get all the vocabularies and their id's with this function:

/**
 * Return an array of all vocabulary objects.
 *
 * @param $type
 *   If set, return only those vocabularies associated with this node type.
 */
function taxonomy_get_vocabularies($type = NULL)

or if you know the vocabulary id you would get the vocabulary with this function:

function taxonomy_get_vocabulary($vid)

or if you want the whole tree:

/**
 * Create a hierarchical representation of a vocabulary.
 *
 * @param $vid
 *   Which vocabulary to generate the tree for.
 *
 * @param $parent
 *   The term ID under which to generate the tree. If 0, generate the tree
 *   for the entire vocabulary.
 * ...
 */
function taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL) {

Fetch the term object for that term id:

function taxonomy_get_term($tid)

Here is a full example (without any formating of the output) of how it could be done:

$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $vocabulary) {
  echo 'vocabulary name:' . $vocabulary->name;
  $tree = taxonomy_get_tree($vocabulary->vid);
  foreach ($tree as $term) {
    // we're just fetching node titles and a few other fields here.
    $sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid = '. $term->tid .' AND n.status = 1 ORDER BY n.changed';
    $result = db_query(db_rewrite_sql($sql));
    while ($node = db_fetch_object($result)) {
      echo '<pre>';
      print_r($node);
      echo '</pre>';      
    }
  }
}
kingandy’s picture

I just wanted to mention that the SQL code in your full example helped me bring back nodes-in-a-term for theming my taxonomy_context site. Thanks loads!

++Andy

pielgrzym’s picture

Try using the Views module. You can create a block or page with the list of nodes (or a table) filtered using various criteria. For your needs a page with a couple of views blocks would be fine :)

--
Pielgrzym

mokargas’s picture

I ended up doing this, tho every time I need to add a taxonomy term (a new category) I need to add another block :/

But, works good !