WordPress.org

Support

Support » Plugins and Hacks » Download Monitor » [Plugin: WordPress Download Monitor] Hide if no downloads

[Plugin: WordPress Download Monitor] Hide if no downloads

  • betadog

    @betadog

    I am trying to completely hide a <div> that contains my downloads when there are no downloads.

    In my <div> I only show downloads with certain tags like this:

    $dl = '[downloads query="tags=blue,big"]';
    $dl = apply_filters('the_content', $dl);
    echo $dl;

    So, to hide this <div> when there are no matching downloads I thought I’d use something like this:

    $check_dl = get_downloads('query="tags=blue,big"'');
    if ( '' != $check_dl ) {
    $dl = '[downloads query="tags=blue,big"]';
    $dl = apply_filters('the_content', $dl);
    echo $dl;
    }

    Unfortunately, that does not work. Any ideas?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Mike

    @jolley_small

    You can get the output of the shortcode using the do_shortcode() function – then you can use what that returns to check if there are any.

    betadog

    @betadog

    Thanks, Mike, I’ve tried that and after some trial and error I came up with this – amazingly enough it seems to work:

    $check_dl = do_shortcode('[downloads query="tags=blue,big"]');
    if ( '<ul class="dlm_download_list"><li>[Keine Downloads gefunden]</li></ul>' != $check_dl ) {
    (...)

    Now, I am no programmer – but this code has MacGuyver written all over it, no? Is there a bette way to do this?

    Mike

    @jolley_small

    You could check for a link perhaps instead? When there are no results there are no links output.

    if (!strstr($check_dl, ‘href’)) {

    }

    Yes, I like that better. Thanks a bunch!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: WordPress Download Monitor] Hide if no downloads’ is closed to new replies.
Skip to toolbar