Display Date Only
-
Hi There,
Really digging this plugin! I was wondering if there was a way to only display the date of an event using a tag similar to eventbrite_event_meta ?
I am wanting to have a small section on my homepage that says “Next Event” and then have the date (like Oct. 15) pulled in automatically.
Thank you!
-
Hm, sounds like you might want to make a small widget or shortcode? Then you just want a query with one result, which happens to be the next event, something like (untested):
<?php // Set up and call our Eventbrite query. $next = new Eventbrite_Query( array( 'limit' => 1 ) ); // Display the result if we have one. if ( $next->have_posts() ) : while ( $next->have_posts() ) : $next->the_post(); ?> <div class="next-event"> <h1><?php esc_html_e( 'Next Event', 'textdomain' ); ?></h1> <p><?php mytheme_next_event_date(); ?></p> </div> <?php endwhile; endif; // Return $post to its rightful owner. wp_reset_postdata(); ?>Then you could make
mytheme_next_event_date()whatever you like, based oneventbrite_event_meta().Hey, thanks for the reply!
I’m able to pull in the loop using this code…
<?php // Set up and call our Eventbrite query. $events = new Eventbrite_Query( apply_filters( 'eventbrite_query_args', array( // 'display_private' => false, // boolean // 'nopaging' => false, // boolean 'limit' => 1, // integer // 'organizer_id' => null, // integer // 'p' => true, // integer // 'post__not_in' => null, // array of integers // 'venue_id' => null, // integer // 'category_id' => null, // integer // 'subcategory_id' => null, // integer // 'format_id' => null, // integer ) ) ); if ( $events->have_posts() ) : while ( $events->have_posts() ) : $events->the_post(); ?> <div>next seminar</div> <div><?php eventbrite_event_meta(); ?></div> <?php endwhile; endif; ?>The problem is that brings in too much information (date, time, etc). Is there a way to only display the date?
Thanks so much!
I too would like to know the answer to this.
I have a site where the venue (probably) and organiser is always going to be the same so I just want the date and time showing in the listing page and the venue info to show in the single page
Is there any way to separate the meta to show date and time only ?
Thanks in advance
> Is there a way to only display the date?
Sure, replace
eventbrite_event_meta()with a function of your own, based oneventbrite_event_meta(), but without the bits you don’t want (and then use that new function instead in your template.@fibiet is that answer something you know how to do? Because unfortunately I sure don’t!
@fibiet well I said I couldn’t figure it out but then, turns out I could haha.
Here is what worked for me (this goes into your theme’s functions.php file). I was wanting to return only the abbreviated month and day – like so “Oct. 17” so that’s what I modified the function to do.
There is a strong possibility that this could be done much more elegantly and I make no guarantees to the code but it worked for me.
Let me know if you get stuck.
/* BEGIN MY FUNCTION */ if ( ! function_exists( 'eventbrite_event_date' ) ) : /** * Output event information such as date, time, venue, and organizer */ function eventbrite_event_date() { // Determine our separator. $separator = apply_filters( 'eventbrite_meta_separator', '<span class="sep"> · </span>' ); // Start our HTML output with the event time. $time = '<span class="event-time">' . eventbrite_event_day() . '</span>'; // Assemble our HTML. Yugly. $html = sprintf( _x( '%1$s%2$s%3$s%4$s', '%1$s: time, %2$s: venue, %3$s: organizer, %4$s: event details (only on index views)', 'eventbrite-api' ), $time, $venue, $organizer, $details ); echo apply_filters( 'eventbrite_event_date', $html, $time, $venue, $organizer, $details ); } endif; if ( ! function_exists( 'eventbrite_event_day' ) ) : /** * Return an event's time. * * @return string Event time. */ function eventbrite_event_day() { // Determine if the end time needs the date included (in the case of multi-day events). // Assemble the full event time string. $event_time = sprintf( _x( '%1$s %2$s', 'Event date and time. %1$s = start time, %2$s = end time', 'eventbrite_api' ), esc_html( mysql2date( 'M j ', eventbrite_event_start()->local ) ), esc_html( $end_time ) ); return $event_time; } endif; /* END MY FUNCTION */That looks like it would do just fine.
Thanks so much for posting. It’s still not working for me unfortunately. I copied across your code and got it showing the date and end time which I have now changed to show the start time on the index.php page but it is ignoring it on the single.php page. Don’t seem to be able to get it to show on both.
Here is my code:
if ( ! function_exists( 'eventbrite_event_date' ) ) : /** * Output event information such as date, time, venue, and organizer */ function eventbrite_event_date() { // Determine our separator. $separator = apply_filters( 'eventbrite_meta_separator', '<span class="sep"> · </span>' ); // Start our HTML output with the event time. $time = '<span class="event-time">' . eventbrite_event_day() . '</span>'; // Assemble our HTML. Yugly. $html = sprintf( _x( '%1$s%2$s%3$s%4$s', '%1$s: time, %2$s: venue, %3$s: organizer, %4$s: event details (only on index views)', 'eventbrite-api' ), $time, $venue, $organizer, $details ); echo apply_filters( 'eventbrite_event_date', $html, $time, $venue, $organizer, $details ); } endif; if ( ! function_exists( 'eventbrite_event_day' ) ) : /** * Return an event's time. * * @return string Event time. */ function eventbrite_event_day() { // Determine if the end time needs the date included (in the case of multi-day events). $start_time = ( eventbrite_is_multiday_event() ) ? mysql2date( 'j F Y, g:i A', eventbrite_event_start()->local ) : mysql2date( 'g:i A', eventbrite_event_start()->local ); // Assemble the full event time string. $event_time = sprintf( _x( '%1$s %2$s', 'Event date and time. %1$s = start time, %2$s = end time', 'eventbrite_api' ), esc_html( mysql2date( 'j M Y ', eventbrite_event_start()->local ) ), esc_html( $start_time ) ); return $event_time; } endif;I added the following to both my custom template files – index.php and single.php
<div class="entry-meta"> <?php eventbrite_event_day(); ?> </div><!-- .entry-meta -->Any ideas what I could be doing wrong? Failing completely after hours and hours of trying. I think I just don’t understand php functions well enough. hrrrm
Hey @fibiet,
Did you remember to call the Eventbrite query on your single.php page?
It’s this bit…
// Set up and call our Eventbrite query. $events = new Eventbrite_Query( apply_filters( 'eventbrite_query_args', array( // 'display_private' => false, // boolean // 'nopaging' => false, // boolean 'limit' => 1, // integer // 'organizer_id' => null, // integer // 'p' => true, // integer // 'post__not_in' => null, // array of integers // 'venue_id' => null, // integer // 'category_id' => null, // integer // 'subcategory_id' => null, // integer // 'format_id' => null, // integer ) ) );Hi @fireflip
I didn’t do that – just copied across the template that comes with the plugin and altered the header info. Adding this hasn’t helped tho.
Any ideas why I just get the start date and not the end date as well on the index page?
Here is my single page template file as it is now
<?php /** * The Template for displaying all single Eventbrite events. */ get_header(); ?> <div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <?php // Set up and call our Eventbrite query. $events = new Eventbrite_Query( apply_filters( 'eventbrite_query_args', array( // 'display_private' => false, // boolean // 'nopaging' => false, // boolean // 'limit' => null, // integer // 'organizer_id' => null, // integer // 'p' => null, // integer // 'post__not_in' => null, // array of integers // 'venue_id' => null, // integer // 'category_id' => null, // integer // 'subcategory_id' => null, // integer // 'format_id' => null, // integer ) ) ); // Get our event based on the ID passed by query variable. $event = new Eventbrite_Query( array( 'p' => get_query_var( 'eventbrite_id' ) ) ); if ( $event->have_posts() ) : while ( $event->have_posts() ) : $event->the_post(); ?> <article id="event-<?php the_ID(); ?>" <?php post_class(); ?>> <header class="entry-header"> <h1 class="entry-title"><?php the_title(); ?></h1> <?php the_post_thumbnail(); ?> <div class="entry-meta"> <?php eventbrite_event_day(); ?> </div><!-- .entry-meta --> </header><!-- .entry-header --> <div class="entry-content"> <p><?php the_content(); ?></p> <?php eventbrite_ticket_form_widget(); ?> </div><!-- .entry-content --> <footer class="entry-footer"> <?php eventbrite_edit_post_link( __( 'Edit', 'eventbrite_api' ), '<span class="edit-link">', '</span>' ); ?> </footer><!-- .entry-footer --> </article><!-- #post-## --> <?php endwhile; else : // If no content, include the "No posts found" template. get_template_part( 'content', 'none' ); endif; // Return $post to its rightful owner. wp_reset_postdata(); ?> </main><!-- #main --> </div><!-- #primary --> <?php get_sidebar(); ?> <?php get_footer(); ?>
The topic ‘Display Date Only’ is closed to new replies.