WordPress.org

Ready to get started?Download WordPress

Forums

Multi-Column Taxonomy List
Display empty categories as well (7 posts)

  1. Jack
    Member
    Posted 2 years ago #

    Is it possible to make the empty categories display as well? I'd like to show them but style them differently with css. At the moment I'm doing this with get_categories but that will always give me a horizontal list, and I really like this vertical list in columns. Looks much more professional.

    http://wordpress.org/extend/plugins/multi-column-taxonomy-list/

  2. Matthew Muro
    Visual Form Builder Pro
    Plugin Author

    Posted 2 years ago #

    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.

  3. Jack
    Member
    Posted 2 years ago #

    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.

  4. Jack
    Member
    Posted 2 years ago #

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

  5. Matthew Muro
    Visual Form Builder Pro
    Plugin Author

    Posted 2 years ago #

    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?

  6. Jack
    Member
    Posted 2 years ago #

    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

  7. , but keep the name by just calling the cat name.
  • Matthew Muro
    Visual Form Builder Pro
    Plugin Author

    Posted 2 years ago #

    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.

  • Topic Closed

    This topic has been closed to new replies.

    About this Plugin

    About this Topic

    Tags