Modifying Tribe Events Calendar Events List Widget

·

While I have been generally happy with the plugin, I was not impressed with the lack of options that come with the events list widget.

Also, the widget only shows the title of the event and the date directly below.

But, You Can Extend the Events List Widget!

After digging through code for The Events Calendar plugin, I found that the view (controls the display) for the widget is located in /views/widgets/list-widget.php.

Here is the source code for that file taken from the WordPress.org repo on 5-16-2014 :

<?php
/**
 * Events List Widget Template
 * This is the template for the output of the events list widget.
 * All the items are turned on and off through the widget admin.
 * There is currently no default styling, which is needed.
 *
 * This view contains the filters required to create an effective events list widget view.
 *
 * You can recreate an ENTIRELY new events list widget view by doing a template override,
 * and placing a list-widget.php file in a tribe-events/widgets/ directory
 * within your theme directory, which will override the /views/widgets/list-widget.php.
 *
 * You can use any or all filters included in this file or create your own filters in
 * your functions.php. In order to modify or extend a single filter, please see our
 * readme on templates hooks and filters (TO-DO)
 *
 * @return string
 *
 * @package TribeEventsCalendar
 * @since  2.1
 * @author Modern Tribe Inc.
 *
 */
?>

<li class="tribe-events-list-widget-events <?php tribe_events_event_classes() ?>">

    <?php do_action( 'tribe_events_list_widget_before_the_event_title' ); ?>

    <h4 class="entry-title summary">
            <a href="<?php echo tribe_get_event_link(); ?>" rel="bookmark"><?php the_title(); ?></a>
    </h4>

    <?php do_action( 'tribe_events_list_widget_after_the_event_title' ); ?>
    <!-- Event Time -->

    <?php do_action( 'tribe_events_list_widget_before_the_meta' ) ?>

    <div class="duration">
        <?php echo tribe_events_event_schedule_details(); ?>
    </div>

    <?php do_action( 'tribe_events_list_widget_before_the_meta' ) ?>

    <!-- Event Title -->
</li>

First things first, always read the comments! After reading the comments in this file, I became aware that there are two ways to update the events list widget:

  • Create a completely new template
  • Use actions in the functions.php of a theme or in a separate plugin

For my purposes, I only wanted to add a description to each listing, so I decided to just use the actions.

But, if you need a completely new look, you could create a new template file in your theme directory at THEME_DIR/tribe-events/widgets/list-widget.php .

Adding a Description with Actions

Because all I wanted to do was add a description below the datefor each event in the events list widget, my solution was pretty simple.

add_action( 'tribe_events_list_widget_after_the_meta', 'edit_tribe_widget_after_title' );
function edit_tribe_widget_after_title() {
    global $post;
    $event = $post;

    echo wpautop( wp_trim_words( $post->post_content, 12, '&hellip; <a href=' . get_permalink( $event ) . '>Read&nbsp;More &rarr;</a>' ) );
}
Upcoming Events List

This snippet will tie into the action that fires right after the meta in each event item, and it will insert up to 12 words of the description for each event as well as a read more link.

While I hooked into the after_meta action to add a description, you could easily use one of these other actions to modify the events list widget to your needs:

  • tribe_events_list_widget_before_the_event_title
  • tribe_events_list_widget_after_the_event_title
  • tribe_events_list_widget_before_the_meta
  • tribe_events_list_widget_before_the_meta

Because the widget calls tribe_events_event_schedule_details(), you can also use the the tribe_events_event_schedule_details filter to filter what shows up in the meta section.

Questions, Comments, Bugs?

First, there is a bug on line 44 of this plugin (bonus if you can figure out what it is). I checked the GitHub repository and they had already fixed it, it just hasn’t been pushed to the WordPress repository.

If there are any other questions or comments, please leave a comment below. If you see any other bugs than the one mentioned above, please leave a comment below so I can fix it 🙂

Comments

7 responses to “Modifying Tribe Events Calendar Events List Widget”

  1. Michael Avatar
    Michael

    Thanks, I appreciate you getting this description up. It was exactly what I was looking for.

  2. Bob Avatar

    Thanks Eric! I got it to work by adding it to the end of the functions.php file (right before the ?> for us non-programmers). I’m interested in how you dealt with the CSS styling for the widget as the default widget styling is almost unusable. Thanks again!

  3. Josh Avatar

    I want to do something similar… for each event, they also have a ticket. I would like to add the remaining ticket quantity to each event in calendar view. I know this is the code snippet for displaying quantity: get_stock_quantity(); ?>, but I can’t seem to get it to work. any ideas?

  4. Steinar Avatar
    Steinar

    Hi Eric and thank you for your post. I am using the widget on my main landing page, not on the sidebar and I am trying to figure out how to list the events horizontally instead of vertically. Any simple ideas you can think of regarding this, as the events show up and a lot of dead space is showing up at the moment.

    1. ebinnion Avatar

      Hi Steinar,

      I haven’t looked at the Tribe Events widget in about a year I believe. That being said, I would probably approach this with CSS.

      Once the HTML markup is in the page, you should be able to float each event within its container so that they are side by side.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Eric Binnion

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from Eric Binnion

Subscribe now to keep reading and get access to the full archive.

Continue reading