links to Media Library content in sidebar per page

Using the Download Monitor plugin allows me to categorize files, so I put my files in there instead of the Media Library. I organize files into categories based on which pages I want to display them. Then, I use a text widget with a custom shortcode to display files per category per page.

In my theme’s functions.php:

// Enable shortcodes in text widgets
add_filter('widget_text', 'do_shortcode');

// Custom shortcode:
add_shortcode('downloads_by_page', 'downloads_by_page');
function downloads_by_page($atts) {
    $atts = shortcode_atts(
        array(
            'pages' => array(),
            'category' => -1, // ID of a Download Monitor category
            'format' => '5' // ID of a Download Monitor output format
        ),
        $atts
    );
    $pages = $atts['pages'];
    if (is_string($pages)) {
        $pages = explode(',', $pages);
    }
    if (is_page($pages)) {
        // 'downloads' shortcode comes with Download Monitor:
        // http://mikejolley.com/projects/download-monitor/
        return do_shortcode('[downloads query="category=' . $atts['category'] .
            '&orderby=title&order=asc" format="' . $atts['format'] . '"]');
    }
    return '';
}

In a text widget in my sidebar:

// Category 3 refers to the ID of the Download Monitor category that has cat-related files
// Pages is a comma-separated list of page names or IDs
[downloads_by_page category="3" pages="About Cats,All Animals"]
[downloads_by_page category="4" pages="About Dogs,All Animals,Canine Facts"]