WordPress.org

Ready to get started?Download WordPress

Forums

Download Monitor
Hide if no downloads (5 posts)

  1. betadog
    Member
    Posted 3 years ago #

    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?

  2. Mike
    Member
    Posted 3 years ago #

    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.

  3. betadog
    Member
    Posted 3 years ago #

    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?

  4. Mike
    Member
    Posted 3 years ago #

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

    if (!strstr($check_dl, 'href')) {

    }

  5. betadog
    Member
    Posted 3 years ago #

    Yes, I like that better. Thanks a bunch!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic