I'm planning the Drupal 6 port of Taxonomy Filter, and taking the opportunity to refactor it a lot in the process. The current module has turned into a bit of a monster over time and outgrown the original design.

Current ideas: Split it into multiple modules - eg a core API module and some submodules for the more advanced menu types. Possibly even split off certain bits of functionality (eg counting nodes in results) into optional extra modules. The idea is to both simplify the codebase (though the overall design will be more ambitious) and also allow other developers to easily add their own menu types or tweak existing functionality with their own modules. Also I'd like to make full use of the Drupal 6 theme function templating and make taxonomy filter more themable.

Any comments?

Comments

styro’s picture

Assigned: styro » Unassigned
Priority: Normal » Minor
Status: Active » Postponed

Putting this on the back burner. If anyone else wants to take this on let me know.

styro’s picture

Title: Drupal 6 port » Drupal 6 redesign/rewrite
Assigned: Unassigned » styro
Status: Postponed » Active

I've actually started work on this now :)

davidwebsters’s picture

I am testing your module and have some suggestions:

1. Could you make Multiple taxonomy filter categories? Currently your module is supporting 1,2 path structure. I am talking about 1,2,3,4 and so on path structure.

2. Node counter doesn't work correctly if you have 2 filters and more taxonomy filters.

3. How to set order of taxonomy filter menus.

Could you upload a HEAD version for testing...

Thanks in advance!

styro’s picture

Priority: Minor » Normal

1. Could you make Multiple taxonomy filter categories? Currently your module is supporting 1,2 path structure. I am talking about 1,2,3,4 and so on path structure.

That has come up before: http://drupal.org/node/267578 and http://drupal.org/node/140440 for two examples. You can keep track of that on those issues. The Drupal 5 version won't get this functionality.

The Drupal 6 version will be way more flexible in this way. It should either be able to do this or come with a bundled addon module to enable this way of operating.

2. Node counter doesn't work correctly if you have 2 filters and more taxonomy filters.

Could you file a separate issue for that. Note: you'll need to provide some more details in the new issue about what isn't working and how to reproduce it.

3. How to set order of taxonomy filter menus.

The Drupal 6 version uses the vocabulary weights for that - ie they will appear in the same order as your vocabs do. Not sure if the Drupal 5 version does that. If you really want that in the Drupal 5 version, file a new feature request.

Could you upload a HEAD version for testing...

I intend to upload an alpha version once I have some mostly working code. Note any alphas or betas won't migrate or keep your settings - you may need to create menus as the config data structures change. The final release should be able to migrate your Drupal 5 settings across.

davidwebsters’s picture

I wrote some snippets... The code is not pro but works... It was only written for main catalog categories and 2 filter categories...

INSTRUCTION:

1. Create 3 vocabularies with some terms (one for main catalog categories and 2 for filters) and name them as you wish, for example:

Catalog:
=======
Auto
-- Audi
-- Opel
Cellular
-- Nokia
-- Samsung

Filter 1st
=======
new
used

Filter 2nd
=======
in New-York
in Detroit

Be sure to check the same content type for all these vocabularies (for example, story), make them as required and then create some nodes.

2. Insert this code into template.php file of the currently used theme (by default located here: themes/garland):

function taxonomy_block_catalog_categories() {
// catalog's category is the FIRST element of terms in a taxonomy path like taxonomy/term/15,23,37  --- in this case it is 15
// path structure:  taxonomy/term/catalogs-term,1st-filters-term,2nd-filters-term

	$vid = 1;  // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from

    if ( (arg(0) == 'taxonomy') && (arg(1) == 'term') ) {
        $current_tids = explode(',', arg(2));
		if (is_numeric($current_tids[1])) {
			$first_filters_term = ( ($current_tids[1] > 0) ? ','.$current_tids[1] : ',0');
		}
		if (is_numeric($current_tids[2])) {
			$second_filters_term = ( ($current_tids[2] > 0) ? ','.$current_tids[2] : ',0');
		}
    } else {
		$first_filters_term = ',0';
		$second_filters_term = ',0';
	}

	$items = array();
	$terms = taxonomy_get_tree($vid);
	foreach ( $terms as $term ) {
		$termid = $term->tid;
		$count = taxonomy_term_count_nodes($term->tid, 'story'); // api: taxonomy_term_count_nodes($tid, $type = 0)
		$termdepth = ''; // catalog have nested categories
		for ($i=0; $i<$term->depth; $i++) {
			$termdepth = $termdepth . '&nbsp;&nbsp;&nbsp;&nbsp;';
		}
		$items[] = $termdepth . str_replace('%2C', ',', l($term->name, "taxonomy/term/".$termid.$first_filters_term.$second_filters_term)) . '&nbsp;' . $count;
	}
	if ( count($items) ) {  print theme('item_list', $items); }

}


function taxonomy_block_filter_first() {
// the first filter is the SECOND element of terms in the taxonomy path like taxonomy/term/15,23,37 --- in this case it is 23
// path structure:  taxonomy/term/catalogs-term,1st-filters-term,2nd-filters-term

	$vid = 2;  // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from

    if ( (arg(0) == 'taxonomy') && (arg(1) == 'term') ) {
        $current_tids = explode(',', arg(2));
		if (is_numeric($current_tids[0])) {
			$catalogs_term = $current_tids[0].',';
		}
		if (is_numeric($current_tids[1])) {
			$first_filters_term = $current_tids[1].',';
		}
    } else {
		$catalogs_term = '0,';
		$first_filters_term = '0,';
	}

	$items = array();
	$terms = taxonomy_get_tree($vid);
	foreach ( $terms as $term ) {
		$termid = $term->tid;
		$count = taxonomy_term_count_nodes($termid, 'story'); // taxonomy_term_count_nodes($tid, $type = 0)
		$items[] = str_replace('%2C', ',', l($term->name, "taxonomy/term/".$catalogs_term.$first_filters_term.$termid)) . '&nbsp;' . $count;
	}
	if ( count($items) ) { print theme('item_list', $items); }

}


function taxonomy_block_filter_second() {
// the second filter is the THIRD element of terms in the taxonomy path like taxonomy/term/15,23,37 --- in this case it is 37
// path structure:  taxonomy/term/catalogs-term,1st-filters-term,2nd-filters-term

	$vid = 3;  // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from

    if ( (arg(0) == 'taxonomy') && (arg(1) == 'term') ) {
        $current_tids = explode(',', arg(2));
		if (is_numeric($current_tids[0])) {
			$catalogs_term = $current_tids[0].',';
		}
		if (is_numeric($current_tids[2])) {
			$second_filters_term = ','.$current_tids[2];
		}
    } else {
		$catalogs_term = '0,';
		$second_filters_term = ',0';
	}

	$items = array();
	$terms = taxonomy_get_tree($vid);
	foreach ( $terms as $term ) {
		$termid = $term->tid;
		$count = taxonomy_term_count_nodes($termid, 'story'); // api: taxonomy_term_count_nodes($tid, $type = 0)
		$items[] = str_replace('%2C', ',', l($term->name, "taxonomy/term/".$catalogs_term.$termid.$second_filters_term)) . '&nbsp;' . $count;
	}
	if ( count($items) ) { print theme('item_list', $items); }

}

3. Create 3 different blocks and insert there these codes:

<?php 
// for catalog block
print taxonomy_block_catalog_categories();
?>
<?php
// for first filter block
print taxonomy_block_filter_first();
?>
<?php
// for second filter block
print taxonomy_block_filter_sedond();
?>

Remember to check PHP code input format before submitting new block and then assign a block to a region.

Now browse you catalog and watch an address bar...

davidwebsters’s picture

styro,

Courld you write a correct code to count nodes in currently selected terms?

I have no idea how to do that... Thanks in advance!!!

styro’s picture

Please use separate issues for these questions or posts. This issue is for tracking the version 6 rewrite.

Note:

a) I already have working code (it is in a separate submodule) in the Drupal 6 version for filtering by an arbitrary number of terms.

b) The existing Drupal 5 version already has a function called _taxonomy_filter_count_nodes() for counting how many nodes match a set of terms - look it up. It is very similar to the builtin taxonomy_select_nodes() function.

Once I have the Drupal 6 codebase mostly working and the API / data structures stablised somewhat, I will release an alpha version for people to try out. Hopefully this will only be a week or two away, depending on the time I get to put into it.

styro’s picture

Status: Active » Fixed

A Drupal 6 development snapshot is now available.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.