I have a bunch of PDF files in my Media Library and I want to show the relevant ones on a per-page basis in the sidebar. So on the 'About Cats' page, I want ILoveCats.pdf and cat-food.pdf from the Media Library to show up in the sidebar, but not dogsAreGreat.pdf. What would be the best way to do this? I'm using the Genesis framework if that helps. I would like for there to be an explicit connection between a file in the Media Library and the page(s) on which it shows up, so I'd prefer not to have just some hard-coded links in a template file with PHP testing is_page('blah').

  • You need to describe how you want to acchieve that -> what's the connection between page title and pdf title for example. – kaiser Jan 5 '12 at 16:59
  • Ah, sorry. There's not necessarily any connection between a Media Library entry's title and a Page title. I would like to manually set the associations, maybe via ticking checkboxes next to Media Library entries while editing a given Page. – Sarah Vessels Jan 5 '12 at 18:27
  • So your Q is "I want a concept & the code"? – kaiser Jan 5 '12 at 18:31
  • I wondered if there was some combination of existing plugins or widgets that would accomplish this. I tried Googling around and found Widget Logic, which might be useful if there's some other widget for displaying links to Media Library entries. – Sarah Vessels Jan 5 '12 at 20:09

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(
            'pages' => array(),
            'category' => -1, // ID of a Download Monitor category
            'format' => '5' // ID of a Download Monitor output format
    $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"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.