Created
October 2, 2019 12:51
-
-
Save thecodepoetry/9147a3fde859f2b7bb0adc19266b8934 to your computer and use it in GitHub Desktop.
Testimonial with links.
This file contains 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
add_action( 'init', function() { | |
class My_Testimonial_Override extends DT_Shortcode_Testimonials_Masonry { | |
protected function do_shortcode( $atts, $content = '' ) { | |
// Loop query. | |
$post_type = $this->get_att( 'post_type' ); | |
$config = presscore_config(); | |
if ( 'posts' === $post_type ) { | |
$query = $this->get_posts_by_post_type( 'dt_testimonials', $this->get_att( 'posts' ) ); | |
}else { | |
$category_terms = presscore_sanitize_explode_string( $this->get_att( 'category' ) ); | |
$category_field = ( is_numeric( $category_terms[0] ) ? 'term_id' : 'slug' ); | |
$query = $this->get_posts_by_taxonomy( 'dt_testimonials', 'dt_testimonials_category', $category_terms, $category_field ); | |
} | |
$query_new = apply_filters( 'the7_shortcode_query', null, $this->sc_name, $this->atts ); | |
if ( is_a( $query_new, 'WP_Query' ) ) { | |
$query = $query_new; | |
} | |
do_action( 'presscore_before_shortcode_loop', $this->sc_name, $this->atts ); | |
// Remove default masonry posts wrap. | |
presscore_remove_posts_masonry_wrap(); | |
$loading_mode = $this->get_att( 'loading_mode' ); | |
$data_post_limit = '-1'; | |
switch ( $loading_mode ) { | |
case 'js_pagination': | |
$data_post_limit = $this->get_att( 'jsp_posts_per_page', get_option( 'posts_per_page' ) ); | |
break; | |
case 'js_more': | |
$data_post_limit = $this->get_att( 'jsm_posts_per_page', get_option( 'posts_per_page' ) ); | |
break; | |
case 'js_lazy_loading': | |
$data_post_limit = $this->get_att( 'jsl_posts_per_page', get_option( 'posts_per_page' ) ); | |
break; | |
} | |
if ( 'disabled' == $loading_mode ) { | |
$data_pagination_mode = 'none'; | |
} else if ( in_array( $loading_mode, array( 'js_more', 'js_lazy_loading' ) ) ) { | |
$data_pagination_mode = 'load-more'; | |
} else { | |
$data_pagination_mode = 'pages'; | |
} | |
$data_atts = array( | |
'data-post-limit="' . intval( $data_post_limit ) . '"', | |
'data-pagination-mode="' . esc_attr( $data_pagination_mode ) . '"', | |
); | |
$data_atts = $this->add_responsiveness_data_atts( $data_atts ); | |
echo '<div ' . $this->get_container_html_class( 'dt-testimonials-masonry-shortcode dt-testimonials-shortcode' ) . presscore_masonry_container_data_atts( $data_atts ) . '>'; | |
// Posts filter. | |
$filter_class = array( 'iso-filter' ); | |
if ( 'standard' === $loading_mode ) { | |
$filter_class[] = 'without-isotope'; | |
} | |
$filter_class[] = 'extras-off'; | |
$config = presscore_config(); | |
switch ( $config->get( 'template.posts_filter.style' ) ) { | |
case 'minimal': | |
$filter_class[] = 'filter-bg-decoration'; | |
break; | |
case 'material': | |
$filter_class[] = 'filter-underline-decoration'; | |
break; | |
} | |
$terms = array(); | |
if ( $this->get_flag( 'show_categories_filter' ) ) { | |
$terms = $this->get_posts_filter_terms( $query ); | |
} | |
DT_Portfolio_Shortcode_HTML::display_posts_filter( $terms, $filter_class ); | |
echo '<div ' . $this->iso_container_class() . '>'; | |
if ( $query->have_posts() ): while( $query->have_posts() ): $query->the_post(); | |
do_action('presscore_before_post'); | |
// Post visibility on the first page. | |
$visibility = 'visible'; | |
if ( $data_post_limit >= 0 && $query->current_post >= $data_post_limit ) { | |
$visibility = 'hidden'; | |
} | |
echo '<div ' . presscore_tpl_masonry_item_wrap_class( $visibility ) . presscore_tpl_masonry_item_wrap_data_attr() . '>'; | |
$post_id = get_the_ID(); | |
echo '<div class="testimonial-item post visible">'; | |
if ( $this->get_att( 'content_layout' ) == 'layout_3' || $this->get_att( 'content_layout' ) == 'layout_4' ) { | |
echo '<div class="testimonial-author">'; | |
} | |
if( $this->get_att( 'show_avatar' ) == 'y') { | |
$proportion = 0; | |
$value = explode( ' ', $this->get_att( 'image_paddings' ) ); | |
$padding_right = isset($value[1]) ? $value[1] : 0; | |
$padding_left = isset($value[3]) ? $value[3] : 0; | |
if ( 'resize' === $this->get_att( 'image_sizing' ) ) { | |
$proportion = $this->get_proportion( $this->get_att( 'resized_image_dimensions' ) ); | |
} | |
echo '<div class="testimonial-avatar">'; | |
$img_width = absint( $this->get_att( 'img_max_width', '' ) ); | |
// get link | |
// TODO: Remove links in future. To enable just uncomment. | |
$link = get_the_permalink(); | |
if ( $link ) { | |
$link = esc_url( $link ); | |
} | |
if ( has_post_thumbnail( $post_id ) ) { | |
$thumb_id = get_post_thumbnail_id( $post_id ); | |
$avatar_args = array( | |
'img_meta' => wp_get_attachment_image_src( $thumb_id, 'full' ), | |
'prop' => $proportion, | |
'echo' => false, | |
'wrap' => '<img %IMG_CLASS% %SRC% %SIZE% %IMG_TITLE% %ALT% />', | |
); | |
if ( $img_width ) { | |
$avatar_args['options'] = array( 'w' => $img_width, 'z' => 0 ); | |
} | |
$avatar_wrap_class = 'testimonial-thumb'; | |
if ( presscore_lazy_loading_enabled() ) { | |
$avatar_wrap_class .= ' layzr-bg'; | |
} | |
$avatar = '<span class="' . $avatar_wrap_class . '"><a href="' . $link . '" class="text-primary">' . dt_get_thumb_img( $avatar_args ) . '</a></span>'; | |
} else { | |
$no_avatar_width = $no_avatar_height = $img_width ? $img_width : 60; | |
if ( 'resize' === $this->get_att( 'image_sizing' ) ) { | |
$no_avatar_height = round( $no_avatar_width / $proportion, 2 ); | |
} | |
$avatar = the7_core_testimonials_get_no_avatar( $no_avatar_width, $no_avatar_height ); | |
$avatar = '<span class="testim-no-avatar">' . $avatar . '</span>'; | |
} | |
echo $avatar; | |
echo '</div>'; | |
} | |
if ( $this->get_att( 'content_layout' ) == 'layout_1' || $this->get_att( 'content_layout' ) == 'layout_5' || $this->get_att( 'content_layout' ) == 'layout_6' ) { | |
echo '<div class="content-wrap">'; | |
} | |
echo '<div class="testimonial-vcard">'; | |
if($this->get_att( 'testimonial_name' ) == 'y'){ | |
echo '<div class="testimonial-name">'; | |
// get title | |
$title = get_the_title(); | |
if ( $title ) { | |
$title = '<a href="' . $link . '" class="text-primary"><span>' . $title . '</span></a>'; | |
$title .= '<br />'; | |
} else { | |
$title = ''; | |
} | |
echo $title; | |
echo '</div>'; | |
} | |
echo '<div class="testimonial-position">'; | |
// Output author name | |
// get position | |
$position = get_post_meta( $post_id, '_dt_testimonial_options_position', true ); | |
if ( $position ) { | |
$position = '<span class="text-secondary color-secondary">' . $position . '</span>'; | |
} else { | |
$position = ''; | |
} | |
echo $position; | |
echo '</div>'; | |
echo '</div>'; | |
if ( $this->get_att( 'content_layout' ) == 'layout_3' || $this->get_att( 'content_layout' ) == 'layout_4' ) { | |
echo '</div>'; | |
} | |
// Output description | |
echo '<div class="testimonial-content">' . $this->get_post_excerpt() . '</div>'; | |
if ( $this->get_att( 'content_layout' ) == 'layout_1' || $this->get_att( 'content_layout' ) == 'layout_5' || $this->get_att( 'content_layout' ) == 'layout_6' ) { | |
echo '</div>'; | |
} | |
echo '</div>'; | |
echo '</div>'; | |
do_action('presscore_after_post'); | |
endwhile; endif; | |
echo '</div><!-- iso-container|iso-grid -->'; | |
if ( 'disabled' == $loading_mode ) { | |
// Do not output pagination. | |
} else if ( in_array( $loading_mode, array( 'js_more', 'js_lazy_loading' ) ) ) { | |
// JS load more. | |
echo dt_get_next_page_button( 2, 'paginator paginator-more-button' ); | |
} else if ( 'js_pagination' == $loading_mode ) { | |
// JS pagination. | |
echo '<div class="paginator" role="navigation"></div>'; | |
} else { | |
// Pagination. | |
dt_paginator( $query, array( 'class' => 'paginator' ) ); | |
} | |
echo '</div>'; | |
do_action( 'presscore_after_shortcode_loop', $this->sc_name, $this->atts ); | |
} | |
} | |
add_shortcode( 'dt_testimonials_masonry', array( new My_Testimonial_Override(), 'shortcode' ) ); | |
}, 99 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment