Ready to get started?Download WordPress


Displaying taxonomy filters hierarchically (3 posts)

  1. lelandf
    Posted 8 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.


  2. function5
    Posted 6 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
    Posted 4 months 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
    ) );

    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);
    		array_splice($result, $i, 0, $temp);
    		$parent = $result[$i]->term_id;
    		$depth = $result[$i]->depth + 1;
    	} while ($i++ < count($result));
    	$terms = $result;


You must log in to post.

About this Plugin

About this Topic


No tags yet.