Forums

[resolved] Is there a better way of doing this? (conditional use of Event Calendar plugin) (3 posts)

  1. mat8iou
    Member
    Posted 1 year ago #

    I am using the Event Calendar plugin to display up coming events in the sidebar of my blog. The thing is that a lot of the time, there aren't any up-coming events, so I don't really want a box near the top of my sidebar saying "No events" - I'd prefer if it just disappeared in these circumstances.

    Anyway, I searched the plugin documentation & found no obvious solution for this - so ended up creating some PHP code to capture the output & show the output conditionally depending on what it contained.

    <?php ob_start(); ?>
     <?php ec3_get_events(5); ?>
     <?php $events_list = ob_get_contents(); ?>
    <?php ob_end_clean(); ?>
    <?php if (!strstr($events_list,'No events')) : ?>
     <li class="events">
      <h2>Upcoming Events</h2>
       <ul>
        <?php echo $events_list; ?>
       </ul>
      </li>
    <?php endif; ?>

    The question is - is this a sensible way of doing what I'm trying to achieve? Or is there a more obvious way that I'm missing?

  2. rboatright
    Member
    Posted 1 year ago #

    that looks effective and clever to me.

    --Rick

  3. mat8iou
    Member
    Posted 1 year ago #

    Thanks

    I was worried that I was missing something far more simple that I could have checked against.

    It works fine anyway - that is the main thing.

Topic Closed

This topic has been closed to new replies.

About this Topic