// Add Shortcode function tribe_latest_upcoming_event_shortcode() { // Get the current date $current_date = date( 'Y-m-d H:i:s' ); // Query the latest upcoming Tribe event post $latest_event = new WP_Query( array( 'post_type' => 'tribe_events', 'posts_per_page' => 1, 'meta_key' => '_EventStartDate', // Custom field for event start date 'meta_value' => $current_date, 'meta_compare' => '>', 'orderby' => 'meta_value', 'order' => 'ASC', ) ); // Check if there are any upcoming events if ( $latest_event->have_posts() ) { $output = '<div class="latest-event">'; while ( $latest_event->have_posts() ) { $latest_event->the_post(); $img = get_the_post_thumbnail_url(get_the_ID(),'full'); if(!empty($img)){ $style = ' style="background-image:url('.$img.')"'; } $output .= '<div class="event_root" '.$style.'><div class="event-content"><h3>' . tribe_get_start_date() . ' - '.tribe_get_start_time().'</h3>'; $output .= '<h2>' . get_the_title() . '</h2></div></div>'; } $output .= '</div>'; } else { // If no upcoming events are found $output = '<p>No upcoming events found</p>'; } // Reset Post Data wp_reset_postdata(); return $output; } add_shortcode( 'latest_event_c2', 'tribe_latest_upcoming_event_shortcode' ); add_action( 'wp_footer', 'footer_script_css' ); function footer_script_css() { ?> <style>.event_root{max-width:365px;display:flex;min-height:275px;border-radius:30px;position:relative;color:#fff;overflow:hidden;align-items:flex-end;background-size:cover;background-repeat:no-repeat}.event_root:before{content:"";position:absolute;top:0;bottom:0;left:0;right:0;background-color:rgba(0,0,0,.3)}.event-content{z-index:1;padding:25px}.event-content h3{font-size:1.2em;font-style:normal;font-weight:700;line-height:normal;margin:0}.event-content h2{font-size:1.7em;line-height:1;font-weight:700}</style> <?php } ?>
Jagdish Sarma Asked question May 16, 2024