欢迎各位兄弟 发布技术文章
这里的技术是共享的
How do you get the path of a taxonomy term by it's tid. I am getting the taxonomy title and tid from the database, but I cannot figure out how to link it to its page. Any pointers?
Did you pass it a term object? (Like that return by taxonomy_get_term($tid))
Pass $termpath to l() if you want a link or url() if you want a path.
<?php
// first, get a term object from a term ID
$term = taxonomy_get_term($tid);
// then, use the term object to get the unaliased path
$taxonomy_path = taxonomy_term_path($term);
// finally, lookup the path alias using drupal_lookup_path()
$taxonomy_path_alias = drupal_lookup_path('alias', $taxonomy_path);
?>
Drupal architect. Dirt Biker.
If you feed $taxonomy_path to either l() or url() there is no need to look up the alias.
For Drupal 7 you can use: taxonomy_term_uri()
<?php
$term = taxonomy_term_load($tid); // load term object
$term_uri = taxonomy_term_uri($term); // get array with path
$term_title = taxonomy_term_title($term);
$term_path = $term_uri['path'];
$link = l($term_title,$term_path);
?>
url('taxonomy/term/' . $tid);
来自 https://drupal.org/node/1016522
If you have a term object you
If you have a term object you can use taxonomy_term_path().