Hi everyone,

Is there a way of making use of the vocabulary description as an introduction to section??

I've tried taxonomy context module, which seemed to work for some taxonomies, i would like something similar but to display the vocabulary descriptions/info.

My thinking is if i can get the 'vid' of the current section [the one being viewed] then i can make a simple block to draw out the vocab description that matches that vid???

a pushing in the right direction would be brilliant [still quite new to drupal's workings]

thanks
Tom

Comments

venkat-rk’s picture

If I remember right, you can do this with the taxonomy vocabulary module available at www.ixis.co.uk/drupal-modules

thomjjames’s picture

hi Ramdak, thanks for the suggestion but i decided to go ahead and do it myself and.............i suceeded!!

my codes pretty messy and i'm sure a better coder could do it far better than me.

here's what i added to the top of my page.tpl

<?php 
//echo 
$a = arg(0);
//echo 
$a1 = arg(1);
//echo 
$a2 = arg(2); 
//echo 
$a3 = arg(3);

if ($a == 'taxonomy' & $a3 == ''){ //if tax and no sub cat
  	
	$result = db_query(db_rewrite_sql("SELECT vid, description FROM {term_data} td WHERE td.tid = %d"), $a2);
	$thevid = db_fetch_object($result);
	$this1 = $thevid->vid;
	//echo $this1;
	if($thevid->description == ""){ //if tax description is empty select vocab description
						
	
	$result = db_query(db_rewrite_sql("SELECT description FROM {vocabulary} v WHERE v.vid = %d"), $this1);
	$num_rows = mysql_num_rows($result);
			if($num_rows > 0){
				$edit_vid = $this1;
				$intro = "yes"; //if there is a description
				$edit_url = "admin/taxonomy/edit/vocabulary/";
				while ($description = db_fetch_object($result)) {
					$vocab_description = $description->description;
				}
			}
	}else{ //if tax description is NOT empty show it
		$vocab_description = $thevid->description;
		$edit_vid = $a2;
		$intro = "yes"; //if there is a description
		$edit_url = "admin/taxonomy/edit/term/";
	}
 }
 
if ($a == 'taxonomy_menu' & $a2 == ''){ //if tax_menu and no sub cat ****CORRECT
		$edit_vid = $a1; 
	 $result = db_query(db_rewrite_sql("SELECT description FROM {vocabulary} v WHERE v.vid = %d"), $a1);
	 $num_rows = mysql_num_rows($result);
			if($num_rows > 0){
				$intro = "yes"; //if there is a description
				$edit_url = "admin/taxonomy/edit/vocabulary/";
				while ($description = db_fetch_object($result)) {
					$vocab_description = $description->description;
				}
			} 
 }
 
 if ($a == 'taxonomy_menu' & $a2 != ''){ //if tax_menu and no sub cat
	$edit_vid = $a2; 
	
	 $result = db_query(db_rewrite_sql("SELECT description FROM {term_data} td WHERE td.tid = %d"), $a2);
	 $num_rows = mysql_num_rows($result);
			if($num_rows > 0){
				$intro = "yes"; //if there is a description
				$edit_url = "admin/taxonomy/edit/term/";
				while ($description = db_fetch_object($result)) {
					$vocab_description = $description->description;
				}
			} 
 }
?>

and then added this to show the output

		<?php if($intro == "yes" & $vocab_description != ""){ //show intro ?>
			<div class="cat_intro"><?php print $vocab_description; ?>
			<?php if (user_access('***')): ?><br />[ <a href="/<?php print $edit_url; ?><?php print $edit_vid; ?>" title="Edit this description">Edit this description</a> ]<?php endif; ?>		
			</div>
		<?php }; ?>

it works for me, so i'm happy!

feel free to take it apart and improve it.

cheers
Tom

______________________________________________
https://tomswebstuff.com

TheWhippinpost’s picture

A site configured with folders, which in-turn, represent new categories/sub-categories, will commonly - as best-practicce - have an index page as its 1st landing page. This serves as a guide/intro/portal, whatever... to the category's content within.

It's both SEO and user--friendly, and makes the information-architects happy too! It's also how the internet "operates" by default. IE... Enter a folder with no designated file, and it defaults to index page.

Having an abstract description of a section's content is expected!

I've been struggling for 2 days to get my category/term description show on these pages and whilst taxonomy_context can do it, it's only a start and not a finished solution (for me at least... and I'd go as far as suggesting, for most, if not all Drupal site-owners)...

The reason is: A new section deserves an intro that is more than just 10 words long. Therefore, when I view a category/term page, each and every link that points to the category page (displayed as, "Posted in: CATEGORY LINK HERE"), has a title attribute that contains the WHOLE description!

This adds considerably to the bloat of a page because, if, for instance, you display 10 teasers on that index page, then you have - probably at minimum - 11 repetitions of the description within the source of that page (with or without the tax_context module)!!

Further to the taxonomy_context module: It seemingly relies on the help block to output. Help blocks have a different (semantic) purpose, and may well be styled differently to stand-out.

The problem, as far as I can make out (and one in which the tax_context module probably hit too), is there's seemingly no (easy) way for a node template file to determine the "context" of where it's going to serve its output, as well as it being difficult to insert (this description) content above other node content (Hence why I believe the tx_context author chose the help block).

I've not tried the solution above so can't comment on its use, though I may well give it a go. It just seems overly intensive for the task in-hand IMO, plus I still need to parse out the title attributes of all the links (as described above).

I hope this is given serious thought by those that administer the core. It really shouldn't be this difficult given that a lot of sites are designed this way.

venkat-rk’s picture

You know, you summed up nearly everything about the limitations of drupal when using taxonomy for structuring sites. It just kills you.

How I wish Jaza could be Superman III and find the time to zap all the category module issues! That module is as close to perfection as you can get for something that does both structure and categorisation right.

But, reality is frustrating and I have also had to return to taxonomy and use taxo_context for the intro stuff. It has some serious problems about which I have written to its author seeking help and you can only hope and pray and pay when you can't code;-)

But, this really frightens me:

(displayed as, "Posted in: CATEGORY LINK HERE"), has a title attribute that contains the WHOLE description!

What!!!

TheWhippinpost’s picture

I should of posted this note yesterday as was my intention:

I worked on it, and have found a (simple) fix... that works for me at least! Please give it a go (on a test site, of course!) if you are faced with this problem.

It does away with the taxonomy_context module in just a few lines of code.

HOWTO: Category description on index pages above teasers without bloated HTML

I'll submit the above to the handbook if the feedback is positive, thanks.

venkat-rk’s picture

Thanks! I will be happy to test the fix.

The link doesn't go anywhere, though.

TheWhippinpost’s picture

Strange! :-s

Sorry about that, try again:

HOWTO: Category description on index pages above teasers without bloated HTML

Thanks Ramdak

Mike

venkat-rk’s picture

Thanks for the link!

jamin0’s picture

At line 1373 in modules/taxonomy/taxonomy.module I replaced

$output =  taxonomy_render_nodes(taxonomy_select_nodes($tids, $terms['operator'], $depth, TRUE));

with

$current = taxonomy_get_term($current->tid);
$output =  $current->description ." ". taxonomy_render_nodes(taxonomy_select_nodes($tids, $terms['operator'], $depth, TRUE));

Of course there is more you can do with this but there it is...
The downside is that you need to reapply this change after any future taxonomy module updates.

Hope this helps...
Jamin

summit’s picture

Subscribing, will this be a patch for core?
With an optional field in the admin?
Greetings,
Martijn

tlarr’s picture

I found this to work better.

I placed this at the top of my page.tpl.php

<?php
$result = db_query("SELECT description FROM {term_data} td WHERE td.name = '%s'", $title);
$term = db_fetch_object($result);
?>

And then placed this where i wanted the description to display

<?php if ($term->description  != ""): ?>
 <p id="description"><?php print $term->description; ?></p>
<?php endif; ?>

this just just a quick way of doing this and probably not the best method but it works.