Custom events loop, trying to add 'no upcoming events message'

Home Forums Calendar Products Events Calendar PRO Custom events loop, trying to add 'no upcoming events message'

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #938049
    benjamin1986
    Participant

    Hi, as title suggests, I’m trying to create a custom event loop containing only content from 1 event specific category. I’ve managed this far, but I’m having trouble adding the code needed so that it displays a ‘no upcoming events’ if no events exist in that category? I’ve looked at ‘list-widget.php’ for example for clues and tried: `<?php
    // No Events were Found
    else:
    ?>
    <p><?php _e( ‘There are no upcoming events at this time.’, ‘tribe-events-calendar’ ) ?></p>
    <?php
    endif;

    But perhaps its in the wrong order? Anyways, here’s the code i’ve got so far:

    `<div class=”events-loop”>

    <?php $loop = new WP_Query( array( ‘post_type’ => ‘tribe_events’, ‘posts_per_page’ => 4,’tax_query’ => array(
    array(
    ‘taxonomy’ => ‘tribe_events_cat’,
    ‘field’ => ‘slug’,
    ‘terms’ => ‘event-type-1’
    )
    ) ) ); ?>

    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <div class=”training-item”>
    <?php do_action( ‘tribe_events_before_the_event_title’ ) ?>
    <h3 class=”tribe-events-list-event-title entry-title summary”>
    ” title=”<?php the_title() ?>” rel=”bookmark”>
    <?php the_title() ?>

    </h3>
    <?php do_action( ‘tribe_events_after_the_event_title’ ) ?>

    <!– Event Meta –>
    <?php do_action( ‘tribe_events_before_the_meta’ ) ?>
    <div class=”tribe-events-event-meta vcard”>
    <div class=”author <?php echo $has_venue_address; ?>”>

    <!– Schedule & Recurrence Details –>
    <div class=”updated published time-details”>
    <?php echo tribe_events_event_schedule_details() ?>
    </div>

    <?php if ( $venue_details ) : ?>
    <!– Venue Display Info –>
    <div class=”tribe-events-venue-details”>
    <?php echo implode( ‘, ‘, $venue_details ); ?>
    </div> <!– .tribe-events-venue-details –>
    <?php endif; ?>

    </div>
    </div><!– .tribe-events-event-meta –>

    <!– Event Image –>
    <?php echo tribe_event_featured_image( ) ?>

    <!– Event Content –>
    <?php do_action( ‘tribe_events_before_the_content’ ) ?>
    <div class=”tribe-events-list-event-description tribe-events-content description entry-summary”>
    <?php the_excerpt() ?>
    ” class=”tribe-events-read-more” rel=”bookmark”><h4><?php _e( ‘View course information / book tickets’, ‘tribe-events-calendar’ ) ?> » </h4>
    </div>
    <!– .tribe-events-list-event-description –>
    <?php do_action( ‘tribe_events_after_the_content’ ) ?>
    </div>

    <?php endwhile;wp_reset_query(); ?>

    </div>

    Thanks,
    Ben

    #938099
    Brian
    Member

    Hi Ben,

    I can help you out there.

    If you add a check for if $loop after the query you could do this:


    if ($loop) {
    //Loop Coding
    } else {
    // no events
    }
    wp_reset_query();

    Let me know if that helps.

    Thanks

    #938170
    benjamin1986
    Participant

    Hey, thanks for the speedy reply, I tried this but didn’t seem to work, apologies if I misunderstood, i’m trying my best to learn about the loop, but can’t figure this particular one out:

    `<div class=”event-loop”>

    <?php $loop = new WP_Query( array( ‘post_type’ => ‘tribe_events’, ‘posts_per_page’ => 4,’tax_query’ => array(
    array(
    ‘taxonomy’ => ‘tribe_events_cat’,
    ‘field’ => ‘slug’,
    ‘terms’ => ‘event-type-a’
    )
    ) ) ); ?>

    <?php if ($loop) : ?>

    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <div class=”training-item”>
    <?php do_action( ‘tribe_events_before_the_event_title’ ) ?>
    <h3 class=”tribe-events-list-event-title entry-title summary”>
    ” title=”<?php the_title() ?>” rel=”bookmark”>
    <?php the_title() ?>

    </h3>
    <?php do_action( ‘tribe_events_after_the_event_title’ ) ?>

    <!– Event Meta –>
    <?php do_action( ‘tribe_events_before_the_meta’ ) ?>
    <div class=”tribe-events-event-meta vcard”>
    <div class=”author <?php echo $has_venue_address; ?>”>

    <!– Schedule & Recurrence Details –>
    <div class=”updated published time-details”>
    <?php echo tribe_events_event_schedule_details() ?>
    </div>

    <?php if ( $venue_details ) : ?>
    <!– Venue Display Info –>
    <div class=”tribe-events-venue-details”>
    <?php echo implode( ‘, ‘, $venue_details ); ?>
    </div> <!– .tribe-events-venue-details –>
    <?php endif; ?>

    </div>
    </div><!– .tribe-events-event-meta –>

    <!– Event Image –>
    <?php echo tribe_event_featured_image( ) ?>

    <!– Event Content –>
    <?php do_action( ‘tribe_events_before_the_content’ ) ?>
    <div class=”tribe-events-list-event-description tribe-events-content description entry-summary”>
    <?php the_excerpt() ?>
    ” class=”tribe-events-read-more” rel=”bookmark”><h4><?php _e( ‘View course information / book tickets’, ‘tribe-events-calendar’ ) ?> » </h4>
    </div>
    <!– .tribe-events-list-event-description –>
    <?php do_action( ‘tribe_events_after_the_content’ ) ?>
    </div>
    <?php endwhile; ?>

    <?php else : ?>

    <p>
    No Events
    </p>

    <?php endif; ?>

    <?php wp_reset_query(); ?>

    #938195
    Brian
    Member

    Hard to say what is going wrong. It could be that if check does not work, I maybe wrong about that working.

    This is the example WordPress gives, maybe that will work:

    <?php
    if ( have_posts() ) {
    while ( have_posts() ) {
    the_post();
    //
    // Post Content here
    //
    } // end while
    } // end if
    ?>

    WordPress has more information on the Loop here:

    http://codex.wordpress.org/The_Loop

    #938226
    benjamin1986
    Participant

    Hi,

    Thanks, I managed to figure it out in the end like this:

    <?php 
    	if ( $loop->have_posts() ) : 
    		while ( $loop->have_posts() ) : 
    		$loop->the_post(); ?>
    
    <---Loop Content--->
    
    <?php endwhile; ?>
    
    <?php else : ?>
    <p>
    No Events
    </p>
    
    <?php endif; ?> 
    <?php wp_reset_query(); ?>
    
    </div>

    So not far off, just had odd bit of code in wrong order.
    Also, how do i add the paste the code neatly into this, rather than the mess I’ve been posting?

    #938227
    benjamin1986
    Participant

    Worked out the code pasting thing.

    Thanks for the assistance

    #938247
    Brian
    Member

    I am glad to see you were able to figure it out and thanks for sharing the coding.

    I am going to go ahead and close this ticket as you marked it resolved. If you have a similar issue or another in the future, please do not hesitate to create a new ticket.

    Thanks!

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Custom events loop, trying to add 'no upcoming events message'’ is closed to new replies.