function testimonial_rotator_single($content) { global $post; // SINGLE TESTIMONIAL if (is_single() and get_post_type() == "testimonial") { $testimonial_id = isset($testimonial_id) ? $testimonial_id : $post->ID; // IF NO ROTATOR ID IS FOUND, GRAB THE FIRST ROTATOR ASSOCIATED if (!isset($rotator_id)) { $rotator_id = get_post_meta($testimonial_id, '_rotator_id', true); $rotator_ids = (array) testimonial_rotator_break_piped_string($rotator_id); $rotator_id = reset($rotator_ids); } $itemreviewed = get_post_meta($rotator_id, '_itemreviewed', true); $img_size = get_post_meta($rotator_id, '_img_size', true); $cite = get_post_meta($testimonial_id, '_cite', true); $has_image = has_post_thumbnail() ? "has-image" : false; $template_name = get_post_meta($rotator_id, '_template', true); $rating = (int) get_post_meta($testimonial_id, '_rating', true); $title_heading = get_post_meta($rotator_id, '_title_heading', true); // SANITIZE if (!trim($template_name)) { $template_name = "default"; } if (!trim($title_heading)) { $title_heading = apply_filters('testimonial_rotator_title_heading', 'h2', $template_name, $rotator_id); } $is_single_page = true; if (!$template_name) { $template_name = apply_filters('testimonial_rotator_single_page_theme', 'default', $post->ID); } // LOOK FOR single-testimonial IN TEMPLATE IN THEME $template = locate_template(array("single-testimonial.php")); if (!$template and $template_name != "default" and $template_name != "longform" and file_exists(dirname(__FILE__) . "/../testimonial-rotator-" . $template_name . "/templates/single-testimonial.php")) { $template = dirname(__FILE__) . "/../testimonial-rotator-" . $template_name . "/templates/single-testimonial.php"; } else { if (file_exists(dirname(__FILE__) . "/templates/{$template_name}/single-testimonial.php")) { $template = dirname(__FILE__) . "/templates/{$template_name}/single-testimonial.php"; } } if ($template) { // NO CUSTOM TEMPLATE, MODIFY THE CONTENT ob_start(); $show_title = apply_filters('testimonial_rotator_single_show_title', false, $template_name, $testimonial_id, $rotator_id); $show_image = apply_filters('testimonial_rotator_single_show_image', false, $template_name, $testimonial_id, $rotator_id); $show_body = true; $show_stars = true; $show_author = true; $show_microdata = true; if ($template) { include $template; } $output = ob_get_contents(); ob_end_clean(); return $output; } else { return testimonial_rotator_error(sprintf(__("The template: %s could be found", "testimonial-rotator"), $template_name)); } } return $content; }
function testimonial_rotator($atts) { global $wp_query; // GET ID $id = isset($atts['id']) ? $atts['id'] : false; // GET ROTATOR if ($id) { $rotator = get_post($id); if (!$rotator) { testimonial_rotator_error(sprintf(__('Rotator could not be found with ID: %d', 'testimonial_rotator'), $id)); } // ROTATOR SLUG $rotator_slug = $rotator->post_name; } else { $rotator_slug = "all"; } // GET OVERRIDE SETTINGS FROM WIDGET OR SHORTCODE $extra_classes = isset($atts['extra_classes']) ? $atts['extra_classes'] : ""; $timeout = (int) isset($atts['timeout']) ? $atts['timeout'] : false; $speed = (int) isset($atts['speed']) ? $atts['speed'] : false; $fx = (int) isset($atts['fx']) ? $atts['fx'] : false; $shuffle = (isset($atts['shuffle']) and $atts['shuffle'] == 1) ? 1 : 0; $post_count = isset($atts['limit']) ? (int) $atts['limit'] : false; $format = isset($atts['format']) ? $atts['format'] : "rotator"; $show_title = isset($atts['hide_title']) ? false : true; $is_widget = isset($atts['is_widget']) ? true : false; $show_size = (isset($atts['show_size']) and $atts['show_size'] == "excerpt") ? "excerpt" : "full"; $title_heading = isset($atts['title_heading']) ? $atts['title_heading'] : apply_filters('testimonial_rotator_title_heading', 'h2'); $show_microdata = isset($atts['hide_microdata']) ? false : true; $auto_height = isset($atts['auto_height']) ? $atts['auto_height'] : apply_filters('testimonial_rotator_auto_height', 'calc'); $vertical_align = (isset($atts['vertical_align']) and $atts['vertical_align'] == 1) ? 1 : 0; $div_selector = isset($atts['div_selector']) ? $atts['div_selector'] : apply_filters('testimonial_rotator_div_selector', '> div.slide'); $pause_on_hover = isset($atts['no_pause_on_hover']) ? 'false' : 'true'; $hide_image = isset($atts['hide_image']) ? true : false; $prev_next = isset($atts['prev_next']) ? true : false; $paged = isset($atts['paged']) ? true : false; $template_name = isset($atts['template']) ? $atts['template'] : 'default'; $img_size = isset($atts['img_size']) ? $atts['img_size'] : false; // SET DEFAULT SETTINGS IF NOT SET if (!$timeout) { $timeout = (int) get_post_meta($id, '_timeout', true); } if (!$speed) { $speed = (int) get_post_meta($id, '_speed', true); } if (!$fx) { $fx = get_post_meta($id, '_fx', true); } if (!$shuffle) { $shuffle = get_post_meta($id, '_shuffle', true); } if (!$vertical_align) { $vertical_align = get_post_meta($id, '_verticalalign', true); } if (!$hide_image) { $hide_image = get_post_meta($id, '_hidefeaturedimage', true); } if (!$prev_next) { $prev_next = get_post_meta($id, '_prevnext', true); } if (!$post_count) { $post_count = (int) get_post_meta($id, '_limit', true); } if (!$template_name) { $template_name = get_post_meta($id, '_template', true); } if (!$img_size) { $img_size = get_post_meta($id, '_img_size', true); } if ($show_microdata) { $hide_microdata = get_post_meta($id, '_hide_microdata', true); $show_microdata = $hide_microdata ? false : true; } // SANATIZE SETTINGS if (!$timeout) { $timeout = 5; } if (!$speed) { $speed = 1; } $timeout = round($timeout * 1000); $speed = round($speed * 1000); $post_count = !$post_count ? -1 : $post_count; if ($format != "rotator") { $prev_next = false; } if (!$img_size) { $img_size = 'thumbnail'; } if ($format == "list" and $prev_next) { $paged = true; } // FILTER AVAILABLE FOR PAUSE ON HOVER // ONE PARAMETER PASSED IS THE ID OF THE ROTATOR $pause_on_hover = apply_filters('testimonial_rotator_hover', $pause_on_hover, $id); // STAR ICON $testimonial_rotator_star = apply_filters('testimonial_rotator_star', 'fa-star', $template_name, $id); // IF ID, QUERY FOR JUST THAT ROTATOR $meta_query = array(); if ($id) { $meta_query = array('relation' => 'OR', array('key' => '_rotator_id', 'value' => $id), array('key' => '_rotator_id', 'value' => '|' . $id . '|', 'compare' => 'LIKE')); } // GET TESTIMONIALS $order_by = $shuffle ? "rand" : "menu_order"; $testimonials_args = array('post_type' => 'testimonial', 'order' => 'ASC', 'orderby' => $order_by, 'posts_per_page' => $post_count, 'meta_query' => $meta_query); if ($paged) { $paged = get_query_var('paged') ? get_query_var('paged') : 1; $testimonials_args['paged'] = $paged; } query_posts(apply_filters('testimonial_rotator_display_args', $testimonials_args, $id)); // ROTATOR CLASSES $cycle_class = $format == "rotator" ? " cycletwo-slideshow" : ""; $rotator_class_prefix = $is_widget ? "_widget" : ""; if ($extra_classes) { $cycle_class .= " {$cycle_class} "; } $cycle_class .= " format-{$format}"; $cycle_class .= " template-{$template_name}"; $extra_wrap_class = ""; // VERTICAL ALIGN $centered = ""; if ($vertical_align) { $centered = " data-cycletwo-center-horz=\"true\" data-cycletwo-center-vert=\"true\" "; } // PREV/NEXT BUTTON $prevnextdata = ""; if ($prev_next) { $prevnextdata = " data-cycletwo-next=\"#testimonial_rotator{$rotator_class_prefix}_wrap_{$id} .testimonial_rotator_next\" data-cycletwo-prev=\"#testimonial_rotator{$rotator_class_prefix}_wrap_{$id} .testimonial_rotator_prev\" "; $extra_wrap_class .= " with-prevnext "; // PREV / NEXT FONT AWESOME ICONS, FILTER READY if ($fx == "scrollVert") { $prev_fa_icon = apply_filters('testimonial_rotator_fa_icon_prev_vert', 'fa-chevron-down', $id); $next_fa_icon = apply_filters('testimonial_rotator_fa_icon_next_vert', 'fa-chevron-up', $id); } else { $prev_fa_icon = apply_filters('testimonial_rotator_fa_icon_prev', 'fa-chevron-left', $id); $next_fa_icon = apply_filters('testimonial_rotator_fa_icon_next', 'fa-chevron-right', $id); } } // SWIPE FILTER $touch_swipe = apply_filters('testimonial_rotator_swipe', 'true', $id); // EXTRA DATA ATTRIBUTE FILTER $extra_data_attributes = apply_filters('testimonial_rotator_data_attributes', '', $template_name, $id); $global_rating = 0; if (have_posts()) { echo "<div id=\"testimonial_rotator{$rotator_class_prefix}_wrap_{$id}\" class=\"testimonial_rotator{$rotator_class_prefix}_wrap{$extra_wrap_class}\">\n"; echo "\t<div id=\"testimonial_rotator{$rotator_class_prefix}_{$id}\" class=\"testimonial_rotator hreview-aggregate{$rotator_class_prefix}{$cycle_class}\" data-cycletwo-timeout=\"{$timeout}\" data-cycletwo-speed=\"{$speed}\" data-cycletwo-pause-on-hover=\"{$pause_on_hover}\" {$centered} data-cycletwo-swipe=\"{$touch_swipe}\" data-cycletwo-fx=\"{$fx}\" data-cycletwo-auto-height=\"{$auto_height}\" {$prevnextdata}data-cycletwo-slides=\"{$div_selector}\" {$extra_data_attributes}>\n"; do_action('testimonial_rotator_slides_before'); $slide_count = 1; while (have_posts()) { the_post(); // HAS IMAGE, CAN BE HIDDEN IN ROTATOR SETTINGS $has_image = has_post_thumbnail() ? "has-image" : false; if ($hide_image) { $has_image = false; } // DATA $itemreviewed = get_post_meta($id, '_itemreviewed', true); $cite = get_post_meta(get_the_ID(), '_cite', true); $rating = (int) get_post_meta(get_the_ID(), '_rating', true); // LOOK FOR TEMPLATE IN THEME $template = locate_template(array("loop-testimonial-{$rotator_slug}.php", "loop-testimonial-{$id}.php", "loop-testimonial.php")); // LOOK IN PLUGIN if (!$template) { $template = dirname(__FILE__) . "/templates/loop-testimonial.php"; } // LOAD TEMPLATE if ($template) { include $template; } // SLIDE COUNTER $slide_count++; } // GLOBAL RATING $post_count = $wp_query->post_count; $global_rating_number = floor($global_rating / $post_count); if ($global_rating_number and $show_microdata) { echo "<div class=\"testimonial_rotator_microdata\">\n"; echo "\t<div class=\"rating\">{$global_rating_number}.0</div>\n"; echo "\t<div class=\"count\">{$post_count}</div>\n"; echo "</div>\n"; } do_action('testimonial_rotator_after'); echo "</div> <!-- #testimonial_rotator{$rotator_class_prefix}_{$id} -->\n"; // PREVIOUS / NEXT if ($prev_next and $post_count > 1) { echo "<div class=\"testimonial_rotator_nav\">"; echo "\t<div class=\"testimonial_rotator_prev\"><i class=\"fa {$prev_fa_icon}\"></i></div>"; echo "\t<div class=\"testimonial_rotator_next\"><i class=\"fa {$next_fa_icon}\"></i></div>"; echo "</div>\n"; } echo "</div><!-- .testimonial_rotator{$rotator_class_prefix}_wrap -->\n\n"; } if ($paged) { echo "<div class=\"testimonial_rotator_paged cf-tr\">"; next_posts_link(__('Next Testimonials', 'testimonial_rotator') . ' <i class="fa fa-angle-double-right"></i>'); previous_posts_link('<i class="fa fa-angle-double-left"></i> ' . __('Previous Testimonials', 'testimonial_rotator')); echo "</div>\n"; } wp_reset_postdata(); wp_reset_query(); }