WordPress.org

Support

Support » Plugins and Hacks » Event Organiser » [Resolved] Sidebar Loop to display Upcoming Events

[Resolved] Sidebar Loop to display Upcoming Events

  • 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>
        <ul>
    
          <?php while (have_posts()) : the_post(); ?>
            <li><a href='<?php the_permalink() ?>'>
              <h5><?php the_title(); ?></h5>
              <p><?php echo excerpt(15); ?></p>
            </a></li>
          <?php endwhile; ?>
    
        </ul>
      </aside>

    Any suggestions would be highly appreciated. Thanks. 🙂

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

    http://wordpress.org/extend/plugins/event-organiser/

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

    @stephenh1988

    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(
         'numberposts'=>5,
         'events_start_after'=>'today',
         'showpastevents'=>true,//Deprecated, but set it to true to play it safe.
      ));
    
    if( $events ){
        global $post;
        foreach( $events as $post ){
             setup_postdata($post);
             ?>
          <li>
               <a href='<?php the_permalink() ?>'>
                 <h5><?php the_title(); ?></h5>
                 <p><?php the_excerpt(); ?></p>
               </a>
               on <?php eo_get_the_start('jS F Y'); ?>
          </li>
             <?php
         }
         wp_reset_postdata();
    }

    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

    @stephenh1988

    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 ‘[Resolved] Sidebar Loop to display Upcoming Events’ is closed to new replies.
Skip to toolbar