Another taxonomy term list for Drupal
June 15th, 2007 tela
In my previous post I exposed one method how to make a list of the taxonomy terms with Drupal. This method was using the Taxonomy Menu module. However this method has some limitations.
One is that it creates specific URL for the menu item link. It doesn’t use the existing URL for the taxonomy term: /taxonomy/term/[term-ID]
It links to a page with a URL that looks like this: /taxonomy_menu/[vocabulary-ID]/[term-ID]
This can be a problem for example when you want to use a module like Pathauto to automatically generate URL aliases. The pages created by the Taxonomy Menu module are not managed by the Pathauto module. So it you want to keep a coherent naming system for your URLs you will need to change manually the URL aliases for these pages.
There is another limitation regarding its “SEO friendliness”. I think it’s always a good thing to use the title attribute in the <a> tag. This feature doesn’t come standard with Taxonomy Menu module. So if you want it, you need to manually edit each menu item to add a description.
Considering these limitations, and a process that is somehow quite complex, I have found another method which involves the use of a php block snippet.
This is a one step method.
You just need to create a new block: go to Administer > Site building > Blocks and click Add block.
Fill in the different fields:
- Block description: this is the text used on the Blocks overview page.
- Block title: this is the title that is displayed on the website.
- Block body: copy and paste the code below:
<?php
$vid = 1; /* <---- put correct vocabulary ID here */
$terms = taxonomy_get_tree($vid);
print "<ul>";
foreach ( $terms as $term ) {
print "<li>".
l($term->name,'taxonomy/term/'.$term->tid, array('title' => $term->name)).
"</li>";
} /* end foreach */
print "</ul>";
?>
- Select the correct Input format under Block body: PHP code.
Save the block.
On the Blocks overview page, locate the newly created block under Disabled. Select where you want to display your block from the dropdown list.
You’re done.
You can see this in action in the last website we created with Drupal: Tela-Group.com
Entry Filed under: Drupal


17 Comments Add your own
Pages: [2] 1 »
17. Richard | July 4th, 2008 at 5:45 pm
Thank you so much for this!
16. tela | July 3rd, 2008 at 1:38 pm
Hi Florent,
I don’t know Drupal6 but I don’t think this has anything to do with the version of Drupal.
I would suggest you look at the list of the input formats available (under Site configuration).
15. Florent | July 3rd, 2008 at 1:01 pm
hi,
i tried your code with D6 but if i paste the php code. i have it on the site. I don’t see option PHP code behind field body…?
An idea
Florent
14. ilaria | February 13th, 2008 at 12:08 pm
Hi, it’s wonderfull…. thanks a lot…
But I need also the menu to be collapsible and to show subterms for two levels. My vocabulary contains 10 terms that have a lot of terms a and subterms….
I can’t work without a collapsibile two level structure!
Taxonomy menu, even if a great module, has two limitation : 1)does not work with pathauto
2) I’cant handle the list of the nodes related to terms and subterms.
So, please, help me!!!!!
13. tela | February 12th, 2008 at 11:28 am
Hi ilaria
I just posted a new code for a taxonomy list with terms and subterms: Taxonomy term list with subterms for Drupal
12. Tela-Web » Taxonomy&hellip | February 12th, 2008 at 9:44 am
[…] Another taxonomy term list for Drupal […]
11. ilaria | February 8th, 2008 at 1:55 pm
It works well for me too!!! thanks!!!
But my taxonomy menu has terms and subterms….
How can I have the same tree structure with collapsible terms links in their subterms links as taxonomy menu does? Sorry for my english…
Pages: [2] 1 »
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed