Home › Forums › Calendar Products › Events Calendar PRO › Custom events loop, trying to add 'no upcoming events message'
- This topic has 6 replies, 2 voices, and was last updated 11 years, 3 months ago by
Brian.
-
AuthorPosts
-
January 27, 2015 at 7:22 am #938049
benjamin1986
ParticipantHi, 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,
BenJanuary 27, 2015 at 8:28 am #938099Brian
MemberHi 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
January 27, 2015 at 10:12 am #938170benjamin1986
ParticipantHey, 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(); ?>
January 27, 2015 at 10:27 am #938195Brian
MemberHard 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:
January 27, 2015 at 12:05 pm #938226benjamin1986
ParticipantHi,
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?January 27, 2015 at 12:06 pm #938227benjamin1986
ParticipantWorked out the code pasting thing.
Thanks for the assistance
January 27, 2015 at 1:03 pm #938247Brian
MemberI 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!
-
AuthorPosts
- The topic ‘Custom events loop, trying to add 'no upcoming events message'’ is closed to new replies.
