Overriding Drupal 6 taxonomy pages HTML output

So you are using the devel module to see what preprocessing and #theming functions are getting called in the page-taxonomy.tpl.php pages in your #Drupal installation (hereafter simply referred to as taxonomy pages). Are you wondering who is generating all that stuff inside the $content variable? Why can't you get an array of $node objects, just like when you get a single $node object when viewing each individual node page? [inline:devel_page_taxonomy.PNG=page-taxonomy.tpl.php $content variable viewed with the devel module]

In the node pages you get a fully populated $node object, which you can then iterate through in your template code and choose what variables to print and where (see below); [inline:node_object.PNG=page-node.tpl.php $node object viewed with the devel module] But in the taxonomy pages you do not get an array of $node objects for example. Instead, all the nodes related to a term are already mashed up in HTML, which may still allow for modifications, but only on the presentation (theming) layer and not on the application (logic) level. So who of all the functions is responsible for generating all that HTML, and how can we override the taxonomy page output? The answer lies in the #Drupal core, so let's dive into it: 1) Line 12, [taxonomy.pages.inc](http://api.drupal.org/api/drupal/modules--taxonomy--taxonomy.pages.inc/6/source "taxonomy.pages.inc") According to the Drupal 6 API [taxonomy_term_page](http://api.drupal.org/api/function/taxonomy_term_page "http://api.drupal.org/api/function/taxonomy_term_page") is "a menu callback that displays all nodes associated with a term". I recommend that you take a look at it in the core, but just to keep it short and jump to the solution, this function calls on line 44 of taxonomy.pages.inc the theme_taxonomy_term_page function: 2) According to the Drupal 6 API, the [theme_taxonomy_term_page](http://api.drupal.org/api/function/theme_taxonomy_term_page/6 "http://api.drupal.org/api/function/theme_taxonomy_term_page/6") function "renders a taxonomy term page with HTML output". So this is the culprit right here for populating $content variable in the taxonomy pages. However, before jumping into creating your theme override function in your theme's template.php or custom module, I highly recommend taking a look into theme_taxonomy_term_page's innards to have an idea of how it is generating it's content, so you can copy and paste into your theme override the code and modify it to your pleasure.

What calling theme('taxonomy_term_page', $tids, $result) does?

1) Calls [taxonomy_get_term($tid)](http://api.drupal.org/api/function/taxonomy_get_term), a function that returns a term object matching a term ID (line 95). Here is basically what taxonomy_get_term($tid) does: 2) Calls [function taxonomy_render_nodes($result)](http://api.drupal.org/api/function/taxonomy_render_nodes) on line 106, where $result is a pager_query() result, such as that performed by taxonomy_select_nodes(). Remember the second argument of the theme_taxonomy_term_page function? It gets constructed first by the taxonomy_term_page function on line 44 using this piece of code: FYI, according to the Drupal 6 API, [function taxonomy_render_nodes($result)](http://api.drupal.org/api/function/taxonomy_render_nodes) "accepts the result of a pager_query() call, such as that performed by taxonomy_select_nodes(), and formats each node along with a pager".

The taxonomy_render_nodes function

This function basically runs a while loop in which a node object is instantiated for every element in the $result argument the function is passed. This is done using [(Take a peek at db_fetch_object's documentation here)](http://api.drupal.org/api/function/db_fetch_object/6) Then inside the while loop, each $node object is transformed from a PHP object into an HTML string like this: nid), 1); ?>[(node_view](http://api.drupal.org/api/function/node_view) and [node_load](http://api.drupal.org/api/function/node_load/6) documentation) After converting the $node objects into HTML, taxonomy_render_nodes creates the pager element using like this:


Finally - The Solution! (What took you so long?)

You could: - Render the taxonomy pages using the Views module. This is very easy to do, and the Views even generates some template (.tpl) suggestions that you can immediately implement in your current theme folder. This is probably one of the fastest paths, and depending on your needs, you may even get away with a solution that requires little or no coding ! - Pop up open in your favorite text editor your current theme's template.php file (every theme should have one). The template.php file is where ideally you could put your theme('taxonomy_term_page', $tids, $result) override. IMPORTANT: Note that you would NOT write directly in template.php, instead you would : - write yourthemename_taxonomy_term_page($tids, $result) { you can copy/paste the contents of function theme_taxonomy_term_page here to begin with something } - or phptemplate_taxonomy_term_page($tids, $result) { function body }. I generally use the phptemplate_ variant, since if you change the theme's name, it will still work =) - Do the same theme overriding as described above, but in your own custom module, instead of the theme's template.php file. This might be a little more complicated if you are not used to working with modules, but it is not that hard for beginners, and I would recommend it if your theme override function becomes too complex, as in #Drupal the theme and template.php represent and deal with the presentation logic, while custom modules handle with the application logic.
--- Some useful reference I used to construct this article: - http://api.drupal.org/api/drupal/modules--taxonomy--taxonomy.pages.inc/6/source - http://api.drupal.org/api/function/taxonomy_term_page - http://api.drupal.org/api/function/theme_taxonomy_term_page/6 - http://api.drupal.org/api/function/taxonomy_render_nodes If you need some help with theming I couldn't recommend you more to read [Addison Berry's](http://www.lullabot.com/about/addison-berry) - [My Aha! moments in Drupal theming](http://www.lullabot.com/articles/my-aha-moments-drupal-theming). Addison is Drupal's Documentation Team Lead and in March 2009 was awarded a Knight Foundation grant to improve Drupal's documentation. So expect to learn some serious theming ninja skills in that article. If you want to take a look at all the theming hooks in #Drupal, then you can also visit http://api.drupal.org/api/group/themeable/6 This is the first "tutorial" or article I write about Drupal, so I'll appreciate any feedback you leave by posting a comment below or by replying to me @alexander_allen in twitter.

Happy theming =D
- Alex

skin tags

Customizing a web page with drupal for a CMS is very difficult especially if you do not have the right skill or the right information, but with this post I definitely learned a lot. thank you alex
by: skin tags

Overriding themable output

Depending on how your site is configured, the HTML code that makes up each page in your site is compiled from the output of various Drupal modules.
If the default HTML markup supplied by any module does not suit the requirements of your theme, you can override some or all of it, so that the resulting page is exactly what you need for your design.
For example, you might decide that for your site, the default search box should have an image of a magnifying glass and that the label on the search button should read "Discover great stuff!" rather than the custom web design default label of "Search". You can completely override the default markup, so that the markup calls for your image file and that the button is labeled the way you want.

meanto

World is dying by economy whether a super power country or the third world. The problem which should be tackled is the people's condition. One of the most disastrous reason that needs to be determined is Health of the people. If anyone wants to enjoy healthy life can take a look around if there is something helpful :)

mediocasa intermediazione
consulenza immobiliare vendita
acquisto usato
catastali mutui