List nodes tagged with a certain term

  • http://drupal.org/node/63859
  • Multiple tags:
    <?php
    // tag to use:
    $tags = "'tag1','tag2','tag3'";

    // maximum number of items to show:
    $count = 6;

    $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title
    FROM {node} n
    INNER JOIN {term_node} tn ON n.nid = tn.nid
    INNER JOIN {term_data} td ON tn.tid = td.tid
    WHERE td.name IN (%s) AND
    n.status = 1
    ORDER BY n.created DESC"
    ),$tags,0,$count);

    while (
    $node = db_fetch_object($result)) {
     
    $items[] = l($node->title, 'node/'. $node->nid);
    }
    $output = theme('item_list', $items);
    print
    $output;
    ?>

Klassifikation