In furtherance of this thread: Display vocabulary description, which seeks a way to display a term's (category) description as the introduction text for each section, or category, within a site.
The goal:
- Site directory structure thus: www.example.com/category/index.htm and; www.example.com/category/sub-category/index.htm
- To display an introductory description for each category (term description) above all sub-page teasers
- Remove (HTML) code-bloat from the link (anchor) title attribute beneath each teaser (currently term description x No. of teasers = lots of repetitive text!)
- Replace removed (HTML) code-bloat with category/section name instead
The taxonomy_context module currently goes part-way to achieving our goals but doesn't address the last two steps and furthermore, relies on the help block to display our description text above out teasers which, apart from not being semantically-correct, could be problematic in themes which utilise a show/hide help system with different style "decorations" (CivicSpace is one such theme).
NOTE #1: I have only used this against the above site structure. If you have a more complex schema, this may not work as intended but it is hoped that, at minimum, you can now easily customise it to your needs.
NOTE #2: Clean URL's is enabled and I have the pathauto module installed.
NOTE #3: Tested only with PHPTemplate theme engine (Drupal's default).
Instructions
Open-up your node.tpl.php file and right underneath the first opening php line...
<?php /* $Id: node.tpl.php,v 1.4.2.3 2005/11/30 21:06:47 robinmonks Exp $ */ ?>
... make-way to copy/paste our first code snippet:
<?php if ( !$page && arg(0)=="taxonomy" || $is_front) /* NOT a node page but a tax or the home page*/ : ?>
<?php
$categories = <a href="http://api.drupal.org/api/4.7/function/taxonomy_node_get_terms" title="API details">taxonomy_node_get_terms($node->nid)</a>;
foreach ($categories as $category) { /* Re-write the category links to avoid code bloat from long link titles (description ) */
$categorylink = <a href="http://api.drupal.org/api/4.7/function/l" title="API details">l</a>(t($category->name), 'taxonomy/term/' . $category->tid, array('title' =>$category->name), NULL, NULL, TRUE) ."\n";
}
?>
<?php if (($id == 1) && !$is_front) /* Place term desc at the top(id) but NOT on home page */ : ?>
<?php print $category->description ?>
<hr />
<?php endif; ?>
<?php endif; ?>
Then, (further down the code) find the following snippet which writes the link under each teaser entry which points to the category's pertinent index page (www.example.com/category/index.htm):
Posted in print $terms