function tfuse_get_upcoming_events($items) { $final_events = array(); $args = array('posts_per_page' => -1, 'post_type' => 'event'); $query = new WP_Query($args); $posts = $query->posts; if (!empty($posts)) { $count = 0; $posts_with_content = array(); foreach ($posts as $post) { $posts_with_content[$post->ID] = $post; $date = tfuse_page_options('event_date', '', $post->ID); if (!empty($date)) { // repeat event $repeat = tfuse_page_options('event_repeat', '', $post->ID); if ($repeat != 'no') { $repeats[$post->ID] = tfuse_page_options('event_repeat', '', $post->ID); } if ($repeat == 'year') { $from = tfuse_page_options('event_date', '', $post->ID); $date = new DateTime($from); $year = (int) $date->format('Y'); $month = $date->format('m'); $day = $date->format('d'); for ($i = 0; $i < 10; $i++) { $permalink = get_permalink($post->ID); $all[$count]['event_id'] = $post->ID; $all[$count]['event_date'] = $year + $i . '-' . $month . '-' . $day; if (strpos($permalink, "?") === false) { $permalink = $permalink . '?date=' . $all[$count]['event_date']; } else { $permalink = $permalink . '&date=' . $all[$count]['event_date']; } $all[$count]['event_permalink'] = $permalink; ++$count; } } elseif ($repeat == 'month') { $from = tfuse_page_options('event_date', '', $post->ID); $day = strtotime($from); for ($i = 0; $i < 10; $i++) { $to = strtotime(date("Y-m-d", $day) . " +" . $i . " month"); $all[$count]['event_id'] = $post->ID; $all[$count]['event_date'] = date("Y-m-d", $to); $permalink = get_permalink($post->ID); if (strpos($permalink, "?") === false) { $permalink = $permalink . '?date=' . $all[$count]['event_date']; } else { $permalink = $permalink . '&date=' . $all[$count]['event_date']; } $all[$count]['event_permalink'] = $permalink; ++$count; } } elseif ($repeat == 'week') { $from = tfuse_page_options('event_date', '', $post->ID); $day = strtotime($from); for ($i = 0; $i < 53; $i++) { $to = strtotime(date("Y-m-d", $day) . " +" . $i . " weeks"); $all[$count]['event_id'] = $post->ID; $all[$count]['event_date'] = date("Y-m-d", $to); $permalink = get_permalink($post->ID); if (strpos($permalink, "?") === false) { $permalink = $permalink . '?date=' . $all[$count]['event_date']; } else { $permalink = $permalink . '&date=' . $all[$count]['event_date']; } $all[$count]['event_permalink'] = $permalink; ++$count; } } elseif ($repeat == 'day') { $from = tfuse_page_options('event_date', '', $post->ID); $day = strtotime($from); for ($i = 0; $i < 365; $i++) { $to = strtotime(date("Y-m-d", $day) . " +" . $i . " days"); $all[$count]['event_id'] = $post->ID; $all[$count]['event_date'] = date("Y-m-d", $to); $permalink = get_permalink($post->ID); if (strpos($permalink, "?") === false) { $permalink = $permalink . '?date=' . $all[$count]['event_date']; } else { $permalink = $permalink . '&date=' . $all[$count]['event_date']; } $all[$count]['event_permalink'] = $permalink; ++$count; } } else { $all[$count]['event_id'] = $post->ID; $all[$count]['event_date'] = tfuse_page_options('event_date', '', $post->ID); $permalink = get_permalink($post->ID); if (strpos($permalink, "?") === false) { $permalink = $permalink . '?date=' . $all[$count]['event_date']; } else { $permalink = $permalink . '&date=' . $all[$count]['event_date']; } $all[$count]['event_permalink'] = $permalink; ++$count; } } } } if (!empty($all)) { $current_date = date("Y-m-d"); $upcoming_events = array(); $count = 0; $sorted = tfuse_aasort($all, 'event_date'); foreach ($sorted as $event) { if ($event['event_date'] > $current_date) { $upcoming_events[$count]['event_id'] = $event['event_id']; $upcoming_events[$count]['event_date'] = $event['event_date']; $upcoming_events[$count]['event_permalink'] = $event['event_permalink']; ++$count; } } $items = (int) $items; $k = 0; for ($i = 0; $i < $items; $i++) { if ($upcoming_events[$i]['event_id'] == null) { continue; } $final_events[$k]['event_id'] = $upcoming_events[$i]['event_id']; $final_events[$k]['event_date'] = $upcoming_events[$i]['event_date']; $final_events[$k]['event_permalink'] = $upcoming_events[$i]['event_permalink']; $final_events[$k]['event_title'] = @$posts_with_content[$upcoming_events[$i]['event_id']]->post_title; // get event excerpt if ($posts_with_content[$upcoming_events[$i]['event_id']]->post_excerpt != '') { $final_events[$k]['event_excerpt'] = @$posts_with_content[$upcoming_events[$i]['event_id']]->post_excerpt; } else { $final_events[$k]['event_excerpt'] = @$posts_with_content[$upcoming_events[$i]['event_id']]->post_content; } $k++; } } return $final_events; }
/** * Upcoming Events * * To override this shortcode in a child theme, copy this file to your child theme's * theme_config/extensions/shortcodes/shortcodes/ folder. * */ function tfuse_upcoming_events($atts, $content = null) { tfuse_archive_events(); extract(shortcode_atts(array('items' => 3, 'title' => 'Popular Posts', 'link' => '', 'cat' => ''), $atts)); $return_html = ''; $saved_events = get_option(TF_THEME_PREFIX . '_all_array_events_' . $cat, ''); $uniq = rand(1, 100); $return_html .= '<div id="upcoming_events_load"></div> <input type="hidden" value="' . $cat . '" name="current_event" />'; $current_date = date("Y-m-d"); if (!empty($saved_events)) { $upcoming_events = $final_events = array(); $count = 0; $sorted = tfuse_aasort($saved_events, 'event_date'); foreach ($sorted as $event) { if ($event['event_date'] > $current_date) { $upcoming_events[$count]['event_id'] = $event['event_id']; $upcoming_events[$count]['event_date'] = $event['event_date']; ++$count; } } $items = (int) $items; $k = 0; for ($i = 0; $i < $items; $i++) { if ($upcoming_events[$i]['event_id']) { $final_events[$k]['event_id'] = $upcoming_events[$i]['event_id']; $final_events[$k]['event_date'] = $upcoming_events[$i]['event_date']; $k++; } } } $return_html .= '<section class="upcoming-events"> <div class="container"> <div class="row"> <div class="col-md-12"> <div class="event-slide"> <div class="event-carousel"> <div id="myCarousel' . $uniq . '" >'; $return_html .= '<div class="col-md-6 col-sm-12 col-xs-12"> <div class="events"> <h3 class="section-title">' . $title . '</h3>'; if (!empty($link)) { $return_html .= ' <a href="' . $link . '" class="view-all" >' . __('View all', 'tfuse') . ' <span>+</span></a>'; } $return_html .= '<div class="events-navigation">'; if (!empty($final_events)) { $return_html .= '<ol class="carousel-indicators">'; $c = 0; foreach ($final_events as $event) { $active = $c == 0 ? 'active' : ""; $return_html .= ' <li data-target="#myCarousel' . $uniq . '" data-slide-to="' . $c . '" class="' . $active . '"> <i class="icon-calendar"></i> <div class="title-date"> <div class="event-date">' . $event['event_date'] . '</div> <h3 class="section-title">' . get_the_title($event['event_id']) . '</h3> </div> </li>'; $c++; } $return_html .= '</ol>'; } $return_html .= '</div></div>'; $return_html .= '</div>'; $return_html .= '<div class="carousel-inner col-md-6 col-sm-12 col-xs-12">'; if (!empty($final_events)) { $count = 0; foreach ($final_events as $event) { $act = $count == 0 ? 'active' : ""; $current_post = get_post($event['event_id']); $return_html .= '<div class="' . $act . ' item"> <div class="container"> <div class="wrapp-event-slider-text" data-animate-in="fadeIn" data-animate-out="fadeOut"> <div class="event-date">' . $event['event_date'] . '</div> <h3 class="section-title">' . get_the_title($event['event_id']) . '</h3> <div class="event-content"><p>'; $return_html .= !empty($current_post->post_excerpt) ? $current_post->post_excerpt : strip_tags(tfuse_shorten_string(apply_filters('the_content', $current_post->post_content), 150)); $return_html .= '</p></div> <a href="' . get_permalink($event['event_id']) . '" class="btn btn-transparent btn-event"><span>' . __('Event details', 'tfuse') . ' <i class="icon-chevron-right align-right-icon"></i></span></a> </div> </div> </div>'; $count++; } } $return_html .= '</div>'; $return_html .= '</div></div></div></div></div></div></section>'; $return_html .= "\r\n <script>\r\n\t\t\tjQuery(document).ready(function(\$) {\r\n\t\t\t\t//Event Slider\r\n\r\n\t\t\t\tvar slider2 = jQuery('#myCarousel" . $uniq . "'),\r\n\t\t\t\t\t\tanimateClass;\r\n\t\t\t\tslider2.carousel({\r\n\t\t\t\t\tinterval: 0,\r\n\t\t\t\t\tpause: 'none'\r\n\t\t\t\t});\r\n\t\t\t\tslider2.find('[data-animate-in]').addClass('animated');\r\n\r\n\t\t\t\tfunction animateSlideEvents() {\r\n\t\t\t\t\tslider2.find('.item').removeClass('current');\r\n\r\n\t\t\t\t\tslider2.find('.active').addClass('current').find('[data-animate-in]').each(function () {\r\n\t\t\t\t\t\tvar _this = jQuery(this);\r\n\t\t\t\t\t\tanimateClass = _this.data('animate-in');\r\n\t\t\t\t\t\t_this.addClass(animateClass)\r\n\t\t\t\t\t});\r\n\r\n\t\t\t\t\tslider2.find('.active').find('[data-animate-out]').each(function () {\r\n\t\t\t\t\t\tvar _this = jQuery(this);\r\n\t\t\t\t\t\tanimateClass = _this.data('animate-out');\r\n\t\t\t\t\t\t_this.removeClass(animateClass)\r\n\t\t\t\t\t});\r\n\t\t\t\t}\r\n\t\t\t\tfunction animateSlideEndEvents() {\r\n\t\t\t\t\tslider2.find('.active').find('[data-animate-in]').each(function () {\r\n\t\t\t\t\t\tvar _this = jQuery(this);\r\n\t\t\t\t\t\tanimateClass = _this.data('animate-in');\r\n\t\t\t\t\t\t_this.removeClass(animateClass)\r\n\t\t\t\t\t});\r\n\t\t\t\t\tslider2.find('.active').find('[data-animate-out]').each(function () {\r\n\t\t\t\t\t\tvar _this = jQuery(this);\r\n\t\t\t\t\t\tanimateClass = _this.data('animate-out');\r\n\t\t\t\t\t\t_this.addClass(animateClass)\r\n\t\t\t\t\t});\r\n\t\t\t\t}\r\n\t\t\t\tslider2.find('.invisible').removeClass('invisible');\r\n\t\t\t\tanimateSlideEvents();\r\n\r\n\t\t\t\tslider2.on('slid.bs.carousel', function () {\r\n\t\t\t\t\tanimateSlideEvents();\r\n\t\t\t\t});\r\n\t\t\t\tslider2.on('slide.bs.carousel', function () {\r\n\t\t\t\t\tanimateSlideEndEvents();\r\n\t\t\t\t});\r\n\r\n\t\t\t\tif (Modernizr.touch) {\r\n\t\t\t\t\tslider2.find('.carousel-inner').swipe( {\r\n\t\t\t\t\t\tswipeLeft: function() {\r\n jQuery(this).parent().carousel('prev');\r\n\t\t\t\t\t\t},\r\n\t\t\t\t\t\tswipeRight: function() {\r\n jQuery(this).parent().carousel('next');\r\n\t\t\t\t\t\t},\r\n\t\t\t\t\t\tthreshold: 30\r\n\t\t\t\t\t})\r\n\t\t\t\t}\r\n\t\t\t});\r\n\r\n\t\t</script>\r\n "; return $return_html; }