Display Sub-terms In Drupal Term Page

After working with Drupal in the last two months I’ve really got used to searching for modules for every problem I face and installing them.
While I was working on iCommunity website, I was creating taxonomy terms to categorize the files using them. I created terms with sub terms. The problem was that when browsing a specified term the term page doesn’t display the sub terms of that term.

I searched the internet and found a solution that’s working.
After trying it I decided to try developing a module for doing that (just like the author of the solution suggested).
I’m a newbie in developing for Drupal but I knew how to dig my way through it 😀
(You’d be shocked if you knew that I don’t know PHP 😛 I just write code!)
So before I start this post please this is the first time I write modules, and I learned it yesterday 😛 so if you find any error or something wrong tell me 🙂
I named the module Taxonomy subterms. 😀
So the process is just re-implement the function ‘theme_taxonomy_term_page’ from taxonomy module, but to override it I needed to let Drupal call the function in my module when the user requests ‘/taxonomy/term/’ so to do that I needed to add the ‘hook_menu’ function.

But by doing this I discovered that the Taxonomy module won’t handle the page, so I couldn’t find a way to tell Taxonomy module to handle the page and my module to complete the handling 🙁 So I copied the ‘taxonomy_term_page’ function and renamed it to ‘taxonomy_subterms_term_page’
Then I re-implemented the ‘theme_taxonomy_term_page’ function so I can add the sub-terms section (just like the solution I mentioned did):

Then I had my module working and installed it in the website (you can check it out here. The page is in Arabic but you can easily find the sub terms).

Download

You can download the module here (I didn’t maintain a project @ Drupal because I’m not yet ready to do that, this is just a small experiment).

3 thoughts on “Display Sub-terms In Drupal Term Page

    1. Welcome,
      Everything is possible, you just need to edit the appropriate code or add the functionality to the module, I’m sorry that I can’t do it for you because I left Drupal since I wrote this post and I don’t remember much of it now.

Leave a Reply