Last active
August 29, 2015 14:15
-
-
Save safranck/c3011843aaf0c832286f to your computer and use it in GitHub Desktop.
Grab the testimonials
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Display testimonials | |
*/ | |
function wds_testimonials( $type = '' ) { | |
// Grab the type set for this layout | |
$type = esc_html( get_post_meta( get_the_ID(), '_wds_meltwater_type_select', true ) ); | |
echo wds_get_testimonials( $type ); | |
} | |
/** | |
* Grab the testimonials | |
*/ | |
function wds_get_testimonials( $type ) { | |
// Grab the type set for this layout | |
$type = $type ? $type : esc_html( get_post_meta( get_the_ID(), '_wds_type_select', true ) ); | |
// Grab the posts per page | |
$posts_per_page = get_post_meta( get_the_ID(), '_wds_posts_per_page', true ); | |
// Query for our posts | |
if ( isset( $_GET['delete-trans'] ) || ! ( $testimonials = get_transient( 'wds_featured_testimonials' ) ) ) { | |
$post_args = array( | |
'post_type' => 'testimonial', | |
'posts_per_page' => intval( $posts_per_page ), | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'type', | |
'field' => 'slug', | |
'terms' => $type, | |
), | |
), | |
// 'meta_key' => '_wds_featured', | |
// 'meta_value' => 'on' | |
); | |
$testimonials = new WP_Query( $post_args ); | |
set_transient( 'wds_featured_testimonials', $testimonials, 24 * HOUR_IN_SECONDS ); | |
} | |
if ( ! $testimonials->have_posts() ) { | |
return; | |
} | |
// Enqueue our animate.js file | |
wp_enqueue_script( 'animate' ); | |
$output = '<h1>' . sprintf( __( "What our %s say", "wds" ), $type ) . '</h1>'; | |
$output .= '<div id="testimonials-carousel" class="testimonials-wrap">'; | |
while ( $testimonials->have_posts() ) { | |
$testimonials->the_post(); | |
$thumb = get_the_post_thumbnail( get_the_ID(), 'testimonial' ); | |
$output .= '<div class="testimonial revealOnScroll" data-animation="fadeIn" data-timeout="500">'; | |
$output .= $thumb ? '<div class="customer-avatar">' . $thumb . '</div>' : ''; | |
$output .= '<div class="quote">'; | |
$output .= '<p>' . wp_trim_words( get_the_content(), 16, '' ) . '</p>' | |
. '<div class="customer">' . get_the_title() . '</div></div>'; | |
$output .= '</div>'; | |
} | |
wp_reset_postdata(); | |
$output .= '</div>'; | |
if ($type == 'staff') { | |
$output .= '<p class="footer-link"><a href="#" class="button">' . __( 'Find openings', 'wds' ) . wds_after_button() . '</a></p>'; | |
} else { | |
$output .= '<p class="footer-link"><a href="#" class="button">' . __( 'Case studies', 'wds' ) . wds_after_button() . '</a></p>'; | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment