I'm currently trying to port my site from Drupal 5 to Drupal 6 (and simultaneously form Views 1 to Views 2). With Drupal 5/Views 2 I used the Taxonomy Lineage module to create a block which listed terms in a vocabulary, the number of articles with that term, and a link to a view (viewname/by-term/% where % is the term). Here's an example:

- Term 1 (3) (links to /view/by-term/term-1)
- Term 2 (10) (links to /view/by-term/term-2)

I'd like to replicate this functionality in Drupal 6/Views 2.

I've tried defining a Taxonomy:Term field, but that has two problems. First, the block then lists the term defined for each node in one list. Second, there's no way to define a custom link to the page view - the only option is to link to the default Drupal page for that term. Finally, there's no listing of how many nodes have that term. All of this means I'd rather find a different option.

Is there any way to do this?

CommentFileSizeAuthor
#4 Screenshot25.01 KBcapellic

Comments

merlinofchaos’s picture

The taxonomy lineage module will need to be updated; it stores extra data to get the sorting right, and that extra data is necessary for this to work. Views 2 can't do it by itself.

It's a really simple module, so it shouldn't actually be difficult to port forward. But unfortunately I think the maintainer is AWOL, so we're going to need to find someone willing to do the work.

dblevitan’s picture

Well, I'd be happy to port it to Drupal 6/Views 2. I think I've finished with the Drupal portions, but the views 2 api docs are very basic at the moment and I think I'm going to have to wait until those are expanded more unless there's some better documentation on (for a start) the data structure that hook_views_data is supposed to return.

Thanks.

merlinofchaos’s picture

There's a pretty decent doc on that data structure in the advanced help.

capellic’s picture

StatusFileSize
new25.01 KB

Throw this in a block and change the $vid and the $path and I think you'll be well on your way. You need to create a block for each vocabulary. It only captures parent/child. I could have written it to go recursively, but I'm tired.

<style type="text/css">

	#tax-menu ul 
	{
		margin: 0 0 0 25px;
		padding: 0;
	}

	#tax-menu li {
		list-style-type: none;
		background: none;
		margin: 0;
		padding: 0;
	}
	
	#tax-menu li.tax-menu-item {
		list-style-type: none;
	}
	
	#tax-menu .tax-menu-children {
	}
	
	#tax-menu .tax-menu-children .tax-menu-item {
		list-style-type: square;	
	}
	
</style>


<?php 
$path = 'vendors';
$vid = 2;

// Data
$tax_tree = taxonomy_get_tree($vid);
foreach ($tax_tree as $term)
{
	if ($term->parents[0] == 0)
	{
		$tax_menu[$term->tid]['name'] = $term->name;
		$tax_menu[$term->tid]['views_arg'] = urlencode($term->name);
	}
	else
	{
		foreach ($term->parents as $parent_tid)
		{
			$tax_menu[$parent_tid]['children'][$term->tid]['name'] = $term->name;
			$tax_menu[$parent_tid]['children'][$term->tid]['views_arg'] = urlencode($term->name);
		}
	}
}

// Display
if (!empty($tax_menu))
{
	echo '<ul id="tax-menu">' . "\n";
	foreach ($tax_menu as $term)
	{
		echo '<li class="tax-menu-item"><a href="/' . $path . '/' . $term['views_arg'] . '">' . $term['name'] . '</a></li>' . "\n";
		if (isset($term['children']))
		{
			echo '<ul class="tax-menu-children">' . "\n";
			foreach ($term['children'] as $child)
			{
				echo '<li class="tax-menu-item"><a href="/' . $path . '/' . $child['views_arg'] . '">' . $child['name'] . '</a></li>' . "\n";;
			}
			echo '</ul>' . "\n";
		}
	}
	echo '</ul>' . "\n";
}
?>

See the attachment for a screenshot.

merlinofchaos’s picture

Status: Active » Closed (won't fix)
Justin Freeman’s picture

A Drupal 6 port is available in CVS against HEAD. It's not showing up yet on the module page, but will soon. See http://drupal.org/node/297717