WordPress.org

Ready to get started?Download WordPress

Forums

Facetious
Displaying taxonomy filters hierarchically (3 posts)

  1. lelandf
    Member
    Posted 5 months ago #

    Hey everyone,

    First of all, awesome plugin! Unfortunately I'm struggling a bit with some customization and wanted to post this just to see if anyone had any thoughts.

    Right now Facetious just lists taxonomy filters all one on top of another, seemingly ignoring hierarchy.

    Is it possible to display taxonomy filter dropdowns hierarchically, similar to how WordPress' own wp_dropdown_categories() function handles it?

    I tried stealing some of the code related to the function mentioned above but haven't had any luck so far in making it work with Facetious.

    Any ideas would be greatly appreciated.

    http://wordpress.org/plugins/facetious/

  2. function5
    Member
    Posted 3 months ago #

    I thought I would add to this as I think my question adds to this. Is it possible to manually sort a taxonomy? Currently it just lists the taxonomy terms alphabetically.

  3. tbird12
    Member
    Posted 3 weeks ago #

    I made the category drop-down hierarchical, with counts for categories and tags, with these mods to template.php:

    Look for:
    # Taxonomy dropdown:

    Replace the $terms = get_terms... with:

    $terms = get_terms( $key, array(
    	'hide_empty' => true,
    	'pad_counts' => true
    ) );
    sort_terms_hierarchy($terms);

    Then add this sort_terms_hierarchy function somewhere:

    function sort_terms_hierarchy(Array &$terms) {
    	$result = array();
    	$parent = 0;
    	$depth = 0;
    	$i = 0;
    	do {
    		$temp = array();
    		foreach($terms as $j => $term) {
    			if ($term->parent == $parent) {
    				$term->depth = $depth;
    				$term->name = str_repeat(' ',$depth*4).$term->name.' ('.$term->count.')';
    				array_push($temp, $term);
    				unset($terms[$j]);
    			}
    		}
    		array_splice($result, $i, 0, $temp);
    		$parent = $result[$i]->term_id;
    		$depth = $result[$i]->depth + 1;
    	} while ($i++ < count($result));
    	$terms = $result;
    }

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.