Support » Plugin: Event Organiser » Sidebar Loop to display Upcoming Events

  • Resolved daba


    I’m trying to create a custom sidebar that displays the next 3 upcoming events. This sidebar is to be displayed alongside my blog page and so the code keeps grabbing posts instead of events.

    How could I change my current loop (below) to output events instead of posts? Is this possible?

    <?php query_posts('showposts=3'); ?>
      <aside class="module">
        <h3>Latest News</h3>
          <?php while (have_posts()) : the_post(); ?>
            <li><a href='<?php the_permalink() ?>'>
              <h5><?php the_title(); ?></h5>
              <p><?php echo excerpt(15); ?></p>
          <?php endwhile; ?>

    Any suggestions would be highly appreciated. Thanks. 🙂

    [I’m using a separate function to shorten the excerpt, please ignore that]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Stephen Harris


    Hi daba,

    First you shouldn’t use query_posts().

    In this specific instance, I’d normally suggest get_posts() – but the plug-in provides its own version of that specifically for events: eo_get_events() (see documentation):

    //Get upcoming '
    $events = eo_get_events(array(
         'showpastevents'=>true,//Deprecated, but set it to true to play it safe.
    if( $events ){
        global $post;
        foreach( $events as $post ){
               <a href='<?php the_permalink() ?>'>
                 <h5><?php the_title(); ?></h5>
                 <p><?php the_excerpt(); ?></p>
               on <?php eo_get_the_start('jS F Y'); ?>

    I’ve not tested this, but syntax errors excepting, it should work!



    Yes it works thank you so much.

    Also is is possible to add an else statement to the above loop of yours in order to display something like “No Upcoming Events” when no events are available?

    Sorry, but my php is really basic at the moment…

    Stephen Harris


    Yup just add and else statement. I’ve edited the above example, included an else statement, and made it into this gist.



    Thank you so much and have a great day 😀

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sidebar Loop to display Upcoming Events’ is closed to new replies.