Adding Category to Event List Shortcode Template

WordPress Event Management, Calendars & Registration Forums General Question Adding Category to Event List Shortcode Template

This topic contains 1 reply, has 2 voices, and was last updated by  Stephen Harris 9 years, 11 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #15835

    Can you help me out with how to add the category to the output of the event the comes from the event list shortcode?

    I am using the following, the events are grouped by date, just want to add the categories after the title of each event. Hopefully something like this ‘Parent Category > Child Category’. Thanks for your help!


    <?php
    /**
    * Add this to your theme for it to take affect.
    */
    global $eo_event_loop,$eo_event_loop_args;

    //Date % Time format for events
    $date_format = get_option('date_format');
    $time_format = get_option('time_format');

    //The list ID / classes
    $id = ( $eo_event_loop_args['id'] ? 'id="'.$eo_event_loop_args['id'].'"' : '' );
    $classes = $eo_event_loop_args['class'];

    $current_date = false;

    ?>

    <?php if( $eo_event_loop->have_posts() ): ?>

        <?php while( $eo_event_loop->have_posts() ): $eo_event_loop->the_post(); ?>
    
            <?php 
            if( $current_date != eo_get_the_start('Ymd') ){
    
                if( $current_date ){
                    //End previous group
                    echo '';
                }
    
                //Start new group
                //echo '<h3>'.eo_get_the_start('jS F Y').'</h3>';
                echo '<h3>'.eo_get_the_start('l, F jS, Y').'</h3>';
                echo '
      '; $current_date = eo_get_the_start('Ymd'); } //Generate HTML classes for this event $eo_event_classes = eo_get_event_classes(); //For non-all-day events, include time format $format = ( eo_is_all_day() ? $date_format : $date_format.' '.$time_format ); ?> <li class="<?php echo esc_attr(implode(' ',$eo_event_classes)); ?>" > " title="<?php the_title_attribute(); ?>" ><?php the_title(); ?> <?php echo __('on','eventorganiser') . ' '.eo_get_the_start($format); ?> <?php endwhile; ?>

    <?php elseif( ! empty($eo_event_loop_args['no_events']) ): ?>

    <ul id="<?php echo esc_attr($id);?>" class="<?php echo esc_attr($classes);?>" > 
        <li class="eo-no-events" > <?php echo $eo_event_loop_args['no_events']; ?> 
    
    

    <?php endif; ?>

    Neil Moeller
    #15842

    Hi Neil,

    You can use the standard WordPress api. Event categories are simply terms that belong to the event-category taxonomy. See get_the_term_list() and get_the_terms().

    Regarding formatting the terms as Parent > Child, there is no ‘easy’ way of doing this because events, in general, don’t have one hierarchy of terms. E.g:

    | - Cat A - | - Child Cat A-1
    |           | - Child Cat A-2
    |
    | - Cat B - | - Child Cat B-1
                | - Child Cat B-2
    

    Assuming, that events do have a single hierarchy, the best thing to do is to loop through the array returned by get_the_terms() to pull out the ‘youngest’ term, and then use get_ancestors()

    Stephen Harris
Viewing 2 posts - 1 through 2 (of 2 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.