function single_testimonial_content_filter($content) { global $easy_t_in_widget; //not running in a widget, is running in a single view or archive view such as category, tag, date, the post type is a testimonial if (empty($easy_t_in_widget) && (is_single() || is_archive()) && get_post_type() == 'testimonial') { //load needed data $postid = get_the_ID(); //build array of default attributes //since this is the single testimonial view, go ahead and display all data until we build some options to allow you to set the default display of these items $atts = array('testimonials_link' => get_option('testimonials_link'), 'count' => 1, 'word_limit' => false, 'body_class' => 'testimonial_body', 'author_class' => 'testimonial_author', 'show_title' => 1, 'short_version' => false, 'use_excerpt' => false, 'category' => '', 'show_thumbs' => get_option('testimonials_image'), 'show_rating' => "stars", 'theme' => '', 'show_date' => 1, 'show_other' => 1, 'width' => '100%'); //build and return the single testimonial html $template_content = easy_t_get_single_testimonial_html($postid, $atts, true); return $template_content; } return $content; }
function easy_t_testimonials_grid_shortcode($atts) { // load shortcode attributes into an array // note: these are mostly the same attributes as [testimonials] shortcode $atts = shortcode_atts(array('testimonials_link' => '', 'show_title' => 0, 'count' => -1, 'body_class' => 'testimonial_body', 'author_class' => 'testimonial_author', 'id' => '', 'ids' => '', 'use_excerpt' => false, 'category' => '', 'show_thumbs' => NULL, 'short_version' => false, 'orderby' => 'date', 'order' => 'ASC', 'show_rating' => false, 'paginate' => false, 'testimonials_per_page' => 10, 'theme' => '', 'show_date' => false, 'show_other' => false, 'width' => false, 'cols' => 3, 'grid_width' => false, 'grid_spacing' => false, 'grid_class' => '', 'cell_width' => false, 'responsive' => true, 'equal_height_rows' => false), $atts); extract($atts); // allow ids or id to be passed in if (empty($id) && !empty($ids)) { $id = $ids; } $testimonials_output = ''; $col_counter = 1; $row_counter = 0; if ($equal_height_rows) { wp_enqueue_script('easy-testimonials-grid'); } if (empty($rows)) { $rows = -1; } // make sure $cols is between 1 and 10 $cols = max(1, min(10, intval($cols))); // create CSS for cells (will be same on each cell) $cell_style_attr = ''; $cell_css_rules = array(); if (!empty($grid_spacing) && intval($grid_spacing) > 0) { $coefficient = intval($grid_spacing) / 2; $unit = strpos($grid_spacing, '%') !== false ? '%' : 'px'; $cell_margin = $coefficient . $unit; $cell_css_rules[] = sprintf('margin-left: %s', $cell_margin); $cell_css_rules[] = sprintf('margin-right: %s', $cell_margin); } if (!empty($cell_width) && intval($cell_width) > 0) { $cell_css_rules[] = sprintf('width: %s', $cell_width); } $cell_style_attr = !empty($cell_css_rules) ? sprintf('style="%s"', implode(';', $cell_css_rules)) : ''; // combine the rules into a re-useable opening <div> tag to be used for each cell $cell_div_start = sprintf('<div class="easy_testimonials_grid_cell" %s>', $cell_style_attr); // grab all requested testimonials and build one cell (in HTML) for each // note: using WP_Query instead of get_posts in order to respect pagination // more info: http://wordpress.stackexchange.com/a/191934 $args = array('post_type' => 'testimonial', 'posts_per_page' => $count, 'easy-testimonial-category' => $category, 'orderby' => $orderby, 'order' => $order, 'paged' => get_query_var('paged')); // restrict to specific posts if requested if (!empty($id)) { $args['post__in'] = array_map('intval', explode(',', $id)); } $loop = new WP_Query($args); $in_row = false; while ($loop->have_posts()) { $loop->the_post(); if ($col_counter == 1) { $in_row = true; $row_counter++; $testimonials_output .= sprintf('<div class="easy_testimonials_grid_row easy_testimonials_grid_row_%d">', $row_counter); } $testimonials_output .= $cell_div_start; $postid = get_the_ID(); $testimonials_output .= easy_t_get_single_testimonial_html($postid, $atts); $testimonials_output .= '</div>'; if ($col_counter == $cols) { $in_row = false; $testimonials_output .= '</div><!--easy_testimonials_grid_row-->'; $col_counter = 1; } else { $col_counter++; } } // endwhile; // close any half finished rows if ($in_row) { $testimonials_output .= '</div><!--easy_testimonials_grid_row-->'; } // restore globals to their original values (i.e, $post and friends) wp_reset_postdata(); // setup the grid's CSS, insert the grid of testimonials (the cells) // into the grid, add a clearing div, and return the whole thing $grid_classes = array('easy_testimonials_grid', 'easy_testimonials_grid_' . $cols); if ($responsive) { $grid_classes[] = 'easy_testimonials_grid_responsive'; } if ($equal_height_rows) { $grid_classes[] = 'easy_testimonials_grid_equal_height_rows'; } // add any grid classes specified by the user if (!empty($grid_class)) { $grid_classes = array_merge($grid_classes, explode(' ', $grid_class)); } // combine all classes into an class attribute $grid_class_attr = sprintf('class="%s"', implode(' ', $grid_classes)); // add all style rules for the grid (currently, only specifies width) $grid_css_rules = array(); if (!empty($grid_width) && intval($grid_width) > 0) { $grid_css_rules[] = sprintf('width: %s', $grid_width); } // combine all CSS rules into an HTML style attribute $grid_style_attr = sprintf('style="%s"', implode(';', $grid_css_rules)); // add classes and CSS rules to the grid, insert cells, return result $grid_template = '<div %s %s>%s</div>'; $grid_html = sprintf($grid_template, $grid_class_attr, $grid_style_attr, $testimonials_output); return $grid_html; }