Plugin Directory

Changeset 1271743


Ignore:
Timestamp:
10/23/2015 12:11:50 PM (10 years ago)
Author:
Studiofreya
Message:

menu doesn't list totally empty categories

Location:
sf-category-menu/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sf-category-menu/trunk/readme.txt

    r1260202 r1271743  
    1919* Exclude categories
    2020* Translation ready
     21* Doesn't show empty categories
    2122
    2223= Live demo: =
  • sf-category-menu/trunk/sf-category-menu.php

    r1242718 r1271743  
    55 * Plugin URI: http://studiofreya.com/sf-category-menu/
    66 * Description: Easy treeview menu for WordPress categories.
    7  * Version: 1.2
     7 * Version: 1.3
    88 * Author: Studiofreya AS
    99 * Author URI: http://studiofreya.com
     
    3636}
    3737
    38 function getSubCategoryPostCount( $catid )
    39 {
    40     $num = 0;
    41 
    42     $args = array(
    43         'type'                     => 'post',
    44         'parent'                   => "$catid",
    45         'orderby'                  => 'name',
    46         'order'                    => 'ASC',
    47         'hide_empty'               => 1,
    48         'hierarchical'             => 0,
    49         'exclude'                  => '',
    50         'include'                  => '',
    51         'number'                   => '',
    52         'taxonomy'                 => 'category',
    53         'pad_counts'               => true
    54     );
    55 
    56     $categories = get_categories( $args );
    57 
    58     foreach($categories as $cat)
    59     {
    60         $num += $cat->count;
    61 
    62         $num += getSubCategoryPostCount($cat->cat_ID);
    63     }
    64 
    65     return $num;
    66 }
    67 
    6838function sf_doCategories( $categories, $select_style, $parent = 0 )
    6939{
     
    8858        $ID = $category->cat_ID;
    8959        $subcatcount = sf_getPostCount($ID);
     60       
     61        if($subcatcount < 1) {
     62            continue;
     63        }
    9064
    9165        $category_link = esc_url( get_category_link( $category->term_id ) );
     
    10276        ";
    10377       
     78        $hide_empty = 1;
     79       
     80        if ( $parent == 1 ) {
     81            $hide_empty = 0;
     82        }
     83       
    10484        $childargs = array(
    10585            'parent'            => $ID,
    106             'hide_empty'        => 1,
     86            'hide_empty'        => $hide_empty,
    10787            'hierarchical'      => 0,
    10888            'pad_counts'        => true
     
    138118            'orderby'                  => 'name',
    139119            'order'                    => 'ASC',
    140             'hide_empty'               => 1,
     120            'hide_empty'               => 0,
    141121            'hierarchical'             => 0,
    142122            'exclude'                  => $exclude_categories,
Note: See TracChangeset for help on using the changeset viewer.