• I am customizing widgets, doing okay but I am not sure this last idea is doable.. I have looked at plugins, most widget plugins set them for pages.

    I want a widget that will appear in the sidebar for announcements, recent announcements. I don’t want the widget to show up unless there are posts in a recent date span. It would be dumb to have a sidebar heading “announcements” and then effectively below say, “well okay but none exist right now.”

    I am using right now for another announcements category (company awards) this code:

    <ul class="sidemenu2">
    <?php
    global $post;
    $myposts = get_posts('numberposts=3&meta_key=announce-type&meta_value=awards');
    foreach($myposts as $post) :
    ?>
    <li style="margin-top:6px;margin-right:0;"><?php the_time('M j y'); ?> – <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?php endforeach; ?>
    </ul>

    and it is working fine.

    Am I asking too much of widgets to think I could have it show or not according to a parameter? Is this something I could do with functions.php?

  • The topic ‘display a widget only if post exists in date span AND custom field’ is closed to new replies.