Is there a function to output the tag and vocabulary? $terms = db_query('SELECT vid, name FROM {taxonomy_term_data} WHERE vid=:vid', array(":vid" =&gt; 2));

foreach ($terms as $term) {
    echo l($term-&gt;name, 'taxonomy/term/'.$term-&gt;vid);
}


I want to get all the term under the vocabulary. and the default tag.
If I use the above code to get that, I must know the value of vid, and read the database twice. It's too bad. If someone changes the vocabulary, this will change vid, and my code will not work. Is there a better way to get all the terms in a vocabulary?
There is taxonomy_get_tree() which can return all terms in a hierarchical array, you will however still have to display it and hardcode the vid (or use variable_get() to make it overridable).

Depending on how and where you are displaying this, one of the following alternatives could maybe work better for you:


If you are displaying this information in a block, consider using http://drupal.org/project/taxonomy_menu instead. It can create menus based on vocabularies, which you can then be displayed as a block. They will be properly cached and faster than querying them on every page.
You can also use Views to build a list, tag cloud or similar thing for all terms of a vocabulary.