Show Heirachy of categories in WP Download Monitor

I have the Download Monitor Plugin installed and it works beautifully, I just have a question regarding the categories.

I have a parent category, Issue 0, which will have anywhere from 3-6 sub categories in it. Instead of the section on the front page looking like below, where it just lists every download in the parent category regardless of sub categories,

Read More

categories

How could I make it resemble the structure below, which actually uses the categories, where clicking on the sub category takes you to all of its downloads:

Issue 0 (7) >>

  • News
  • Diabetes
  • Worldview
  • interviews

( These needs to remain as links, like above)

Below is the code for the download_page shortcode, is there a way to incorporate the sub categories into this function?

function wp_dlmp_shortcode_download_page( $atts ) {

    extract(shortcode_atts(array(
        'base_heading_level' => '3',
        'pop_count' => '4',
        'pop_cat_count' => '4',
        'show_uncategorized' => '1',
        'per_page' => '20',
        'format' => '',
        'exclude' => '',
        'exclude_cat' => '',
        'show_tags' => '0',
        'default_order' => 'title',
        'front_order' => 'hits'
    ), $atts));

    $output = wp_dlmp_output($base_heading_level, $pop_count, $pop_cat_count, $show_uncategorized, $per_page, $format, $exclude, $exclude_cat, $show_tags, $default_order, $front_order);
    return $output;

}
add_shortcode('download_page', 'wp_dlmp_shortcode_download_page');
?>

Related posts

Leave a Reply

2 comments

  1. From the documentation and its sample code, I cannot see an option to get the downloads categories tree.

    The function get_downloads returns a one-dimensional array. Maybe a routine could be built to convert it into a multi-dimensional array.

    Use this to see its contents:

    $dl = get_downloads();
    echo '<pre>' . print_r($dl, true ) . '</pre>';
    

    Another possibility is given by a global variable of the plugin that holds all the categories:

    global $download_taxonomies;
    echo '<!-- <pre>' . print_r( $download_taxonomies->categories, true ) . '</pre> -->';
    

    And the results are:

    Array
    (
        [1] => download_category Object
            (
                [id] => 1
                [name] => util
                [parent] => 0
                [decendents] => 
                [direct_decendents] => 
                [size] => 51
            )
    
        [2] => download_category Object
            (
                [id] => 2
                [name] => sys
                [parent] => 0
                [decendents] => Array
                    (
                        [0] => 5
                        [1] => 7
                        [2] => 8
                    )
    
                [direct_decendents] => Array
                    (
                        [0] => 5
                        [1] => 7
                    )
    
                [size] => 3
            )
    
        [5] => download_category Object
            (
                [id] => 5
                [name] => mac
                [parent] => 2
                [decendents] => Array
                    (
                        [0] => 8
                    )
    
                [direct_decendents] => Array
                    (
                        [0] => 8
                    )
    
                [size] => 4
            )
    
        [7] => download_category Object
            (
                [id] => 7
                [name] => windows
                [parent] => 2
                [decendents] => 
                [direct_decendents] => 
                [size] => 0
            )
    
        [8] => download_category Object
            (
                [id] => 8
                [name] => ipad
                [parent] => 5
                [decendents] => 
                [direct_decendents] => 
                [size] => 0
            )
    
    )
    

    Using this array, a logic can be built to iterate through the elements and display the categories hierarchy.

    Demonstration with a shortcode. Note that digforcats has to be a null value:

    add_shortcode('download_cats', 'wpse_73425_download_categories');
    
    function wpse_73425_download_categories( $atts ) 
    {
        global $download_taxonomies;
    
        foreach( $atts as $key=>$value )
            $query .= '&' . $key . '=' . $value;
    
        $the_cats = '<br><br>Download Categories:';
    
        foreach( $download_taxonomies->categories as $category )
        {
            if( $category->parent == 0 )
            {
                $the_cats .= '<br><b>' . $category->name . '</b><br>';
                $dl = get_downloads('category='.$category->id.$query.'&digforcats=');
    
                foreach($dl as $d) 
                {
                    $the_cats .= '<br><a href="'
                    .$d->url . '" title="Version '
                    .$d->version . ' downloaded '
                    .$d->hits.' times" >'
                    .$d->title.' ('.$d->hits.')</a>';
                }
    
                if( isset( $category->direct_decendents ) )
                {
                    foreach( $category->direct_decendents as $cat )
                    {
                        $the_cats .= '<br>- - <i>' 
                        . $download_taxonomies->categories[$cat]->name 
                        . '</i><br>';
    
                       $dl = get_downloads('category='.$cat.$query.'&digforcats=');
    
                        foreach($dl as $d) 
                        {
                            $the_cats .= '<br><a href="'
                            .$d->url.'" title="Version '
                            .$d->version . ' downloaded '
                            .$d->hits.' times" >'
                            .$d->title.' ('.$d->hits.')</a>';
                        }
                    }
                }
            }
        }
        return $the_cats;
    }
    

    Screenshots of the plugin page and the shortcode output:

    plugin settings
    final result

  2. There is very good documentation on the WP Download Monitor available at the author’s website. For what you’re trying to do you need to create a custom format following the examples provided.

    Once you’ve created and saved the format you can specify the format to use in the shortcode or your php call.