WordPress.org

Support

Support » Plugins and Hacks » Multi-Column Taxonomy List » [Plugin: Multi-Column Taxonomy List] Display empty categories as well

[Plugin: Multi-Column Taxonomy List] Display empty categories as well

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Matthew Muro

    @mmuro

    Yes, this is possible.

    Replace lines 103 – 130 with the following:

    /* Extract shortcode attributes, set defaults */
    		extract( shortcode_atts( array(
    			'taxonomy' => 'category',
    			'title' => 'Categories',
    			'title_container' => 'h3',
    			'columns' => '3',
    			'orderby' => 'name',
    			'order' => 'ASC',
    			'show_count' => '0',
    			'exclude' => '',
    			'parent' => '',
    			'rss' => '0',
    			'rss_image' => '',
    			'number' => '',
    			'hide_empty' => '1'
    			), $atts )
    		);
    
    		/* Build an array of arguments for the get_terms parameters */
    		$args = array(
    			'orderby' => $orderby,
    			'order' => $order,
    			'show_count' => $show_count,
    			'exclude' => $exclude,
    			'parent' => $parent,
    			'number' => $number,
    			'hide_empty' => $hide_empty
    		);

    Now you have a ‘hide_empty’ attribute to use in the shortcode. Ex: [mctl hide_empty=0]

    Keep in mind that the links to categories with no posts will result in nothing being found, so make sure your template can handle that if you have lots of categories with no home.

    Great! 😉 Now it would be totally perfect if this list could be filled like with get_categories and foreach. I have this list on my homepage and the categories that are still empty are grey colored. I did this like this:

    $animals = get_categories('hide_empty=0&child_of=2');
    foreach($animals as $animal) {
    	$test = get_posts('category='.$animal->cat_ID);
    	if($test) {
    	echo "<li><a href=\"" . get_category_link($animal->cat_ID) . "?show=map&type=country\"><span>". get_cat_name($animal->cat_ID) ."</span></a></li>";
    	} else {
    	echo "<li class=\"inactive\"><span>". get_cat_name($animal->cat_ID) ."</span></li>";
    	}
    }

    It would be great to be able to do this with columns.

    And with the letters A, B, C etc. seperating the categories alphabetically for the sake of usability and easy viewing 😉

    Plugin Author Matthew Muro

    @mmuro

    I guess you are asking for two things? One, adding a class to those categories that are empty and, two, groupings based on the first letter of the category. Is this correct?

    Yes, that’s correct. The grouping would be good in case of many categories, and the added class for disabling the link, although I’m not sure how this can be done. In the example I gave it’s easy, juste leave out the link in between the

  • , but keep the name by just calling the cat name.
Plugin Author Matthew Muro

@mmuro

I’d suggest turning on the show_count attribute if you want to denote the difference between empty categories or not. I know it’s not a CSS solution, but it should achieve the same thing.

As for the groupings, that’s probably not going to be an option either, sorry.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Multi-Column Taxonomy List] Display empty categories as well’ is closed to new replies.
Skip to toolbar