default.php
3 years ago
grid-hover-layout-archive.php
3 years ago
grid-hover-layout.php
3 years ago
grid-layout-archive.php
3 years ago
grid-layout.php
3 years ago
list-layout-archive.php
3 years ago
list-layout.php
3 years ago
related-post.php
3 years ago
slider-layout-archive.php
3 years ago
slider-layout.php
3 years ago
slider-layout.php
385 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Slider Layout Class |
| 4 | * |
| 5 | * @package RT_TPG |
| 6 | */ |
| 7 | |
| 8 | use RT\ThePostGrid\Helpers\Fns; |
| 9 | |
| 10 | // Do not allow directly accessing this file. |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit( 'This script cannot be accessed directly.' ); |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Slider Layout Class |
| 17 | */ |
| 18 | class TPGSliderLayout extends Custom_Widget_Base { |
| 19 | |
| 20 | /** |
| 21 | * GridLayout constructor. |
| 22 | * |
| 23 | * @param array $data |
| 24 | * @param null $args |
| 25 | * |
| 26 | * @throws \Exception |
| 27 | */ |
| 28 | |
| 29 | public function __construct( $data = [], $args = null ) { |
| 30 | parent::__construct( $data, $args ); |
| 31 | $this->prefix = 'slider'; |
| 32 | $this->tpg_name = esc_html__( 'TPG - Slider Layout', 'the-post-grid' ); |
| 33 | $this->tpg_base = 'tpg-slider-layout'; |
| 34 | $this->tpg_icon = 'eicon-post-slider tpg-grid-icon'; // .tpg-grid-icon class for just style |
| 35 | } |
| 36 | |
| 37 | public function get_script_depends() { |
| 38 | $scripts = []; |
| 39 | |
| 40 | array_push( $scripts, 'imagesloaded' ); |
| 41 | array_push( $scripts, 'swiper' ); |
| 42 | array_push( $scripts, 'rt-tpg' ); |
| 43 | array_push( $scripts, 'rt-tpg-el-pro' ); |
| 44 | |
| 45 | return $scripts; |
| 46 | } |
| 47 | |
| 48 | public function get_style_depends() { |
| 49 | $settings = get_option( rtTPG()->options['settings'] ); |
| 50 | $style = []; |
| 51 | |
| 52 | if ( isset( $settings['tpg_load_script'] ) ) { |
| 53 | array_push( $style, 'rt-fontawsome' ); |
| 54 | array_push( $style, 'rt-tpg-elementor' ); |
| 55 | array_push( $style, 'swiper' ); |
| 56 | } |
| 57 | |
| 58 | return $style; |
| 59 | } |
| 60 | |
| 61 | protected function register_controls() { |
| 62 | /** |
| 63 | * Content Tabs |
| 64 | * ============= |
| 65 | */ |
| 66 | |
| 67 | // Layout. |
| 68 | rtTPGElementorHelper::grid_layouts( $this ); |
| 69 | |
| 70 | // Query. |
| 71 | rtTPGElementorHelper::query( $this ); |
| 72 | |
| 73 | // Links. |
| 74 | rtTPGElementorHelper::links( $this ); |
| 75 | |
| 76 | /** |
| 77 | * Settings Tabs |
| 78 | * ============= |
| 79 | */ |
| 80 | |
| 81 | // Field Selection. |
| 82 | rtTPGElementorHelper::field_selection( $this ); |
| 83 | |
| 84 | // Section Title Settings. |
| 85 | rtTPGElementorHelper::section_title_settings( $this ); |
| 86 | |
| 87 | // Title Settings. |
| 88 | rtTPGElementorHelper::post_title_settings( $this ); |
| 89 | |
| 90 | // Thumbnail Settings. |
| 91 | rtTPGElementorHelper::post_thumbnail_settings( $this ); |
| 92 | |
| 93 | // Excerpt Settings. |
| 94 | rtTPGElementorHelper::post_excerpt_settings( $this ); |
| 95 | |
| 96 | // Meta Settings. |
| 97 | rtTPGElementorHelper::post_meta_settings( $this ); |
| 98 | |
| 99 | // Advanced Custom Field ACF Settings. |
| 100 | rtTPGElementorHelper::tpg_acf_settings( $this ); |
| 101 | |
| 102 | // Readmore Settings. |
| 103 | rtTPGElementorHelper::post_readmore_settings( $this ); |
| 104 | |
| 105 | // Slider Settings. |
| 106 | rtTPGElementorHelper::slider_settings( $this ); |
| 107 | |
| 108 | /** |
| 109 | * Style Tabs |
| 110 | * ============= |
| 111 | */ |
| 112 | |
| 113 | // Section Title. |
| 114 | rtTPGElementorHelper::sectionTitle( $this ); |
| 115 | |
| 116 | // Title Style. |
| 117 | rtTPGElementorHelper::titleStyle( $this ); |
| 118 | |
| 119 | // Thumbnail Style. |
| 120 | rtTPGElementorHelper::thumbnailStyle( $this ); |
| 121 | |
| 122 | // Content Style. |
| 123 | rtTPGElementorHelper::contentStyle( $this ); |
| 124 | |
| 125 | // Meta Info Style. |
| 126 | rtTPGElementorHelper::metaInfoStyle( $this ); |
| 127 | |
| 128 | // Social Style. |
| 129 | rtTPGElementorHelper::socialShareStyle( $this ); |
| 130 | |
| 131 | // ACF Style. |
| 132 | rtTPGElementorHelper::tpg_acf_style( $this ); |
| 133 | |
| 134 | // Read more style. |
| 135 | rtTPGElementorHelper::readmoreStyle( $this ); |
| 136 | |
| 137 | // Slider Style. |
| 138 | rtTPGElementorHelper::slider_style( $this ); |
| 139 | rtTPGElementorHelper::slider_thumb_style( $this ); |
| 140 | |
| 141 | // Link Style. |
| 142 | rtTPGElementorHelper::linkStyle( $this ); |
| 143 | |
| 144 | // Box Settings. |
| 145 | rtTPGElementorHelper::articlBoxSettings( $this ); |
| 146 | |
| 147 | // Promotions. |
| 148 | rtTPGElementorHelper::promotions( $this ); |
| 149 | } |
| 150 | |
| 151 | protected function render() { |
| 152 | $data = $this->get_settings(); |
| 153 | $_prefix = $this->prefix; |
| 154 | if ( ! rtTPG()->hasPro() ) { ?> |
| 155 | <h3 style="text-align: center"><?php echo esc_html__( 'Please upgrade to pro for slider layout!', 'the-post-grid' ); ?></h3> |
| 156 | <?php |
| 157 | return; |
| 158 | } |
| 159 | |
| 160 | if ( rtTPG()->hasPro() && ( 'popup' == $data['post_link_type'] || 'multi_popup' == $data['post_link_type'] ) ) { |
| 161 | wp_enqueue_style( 'rt-magnific-popup' ); |
| 162 | wp_enqueue_script( 'rt-scrollbar' ); |
| 163 | wp_enqueue_script( 'rt-magnific-popup' ); |
| 164 | add_action( 'wp_footer', [ $this, 'get_modal_markup' ], 1 ); |
| 165 | } |
| 166 | |
| 167 | // Query. |
| 168 | $query_args = rtTPGElementorQuery::post_query( $data, $_prefix ); |
| 169 | $query = new WP_Query( $query_args ); |
| 170 | $rand = mt_rand(); |
| 171 | $layoutID = 'rt-tpg-container-' . $rand; |
| 172 | $posts_per_page = $data['post_limit']; |
| 173 | |
| 174 | /** |
| 175 | * TODO: Get Post Data for render post |
| 176 | */ |
| 177 | $post_data = $this->get_render_data_set( $data, $query->max_num_pages, $posts_per_page ); |
| 178 | $_layout = $data[ $_prefix . '_layout' ]; |
| 179 | |
| 180 | $post_data['lazy_load'] = $data['lazyLoad']; |
| 181 | |
| 182 | /** |
| 183 | * Post type render |
| 184 | */ |
| 185 | $post_types = Fns::get_post_types(); |
| 186 | foreach ( $post_types as $post_type => $label ) { |
| 187 | $_taxonomies = get_object_taxonomies( $post_type, 'object' ); |
| 188 | |
| 189 | if ( empty( $_taxonomies ) ) { |
| 190 | continue; |
| 191 | } |
| 192 | |
| 193 | $post_data[ $data['post_type'] . '_taxonomy' ] = isset( $data[ $data['post_type'] . '_taxonomy' ] ) ? $data[ $data['post_type'] . '_taxonomy' ] : ''; |
| 194 | $post_data[ $data['post_type'] . '_tags' ] = isset( $data[ $data['post_type'] . '_tags' ] ) ? $data[ $data['post_type'] . '_tags' ] : ''; |
| 195 | } |
| 196 | |
| 197 | $post_data['enable_2_rows'] = $data['enable_2_rows']; |
| 198 | |
| 199 | $default_gird_column_desktop = '3'; |
| 200 | $default_gird_column_tab = '2'; |
| 201 | $default_gird_column_mobile = '1'; |
| 202 | |
| 203 | if ( $_layout == 'slider-layout13' ) { |
| 204 | $default_gird_column_desktop = '1'; |
| 205 | $default_gird_column_tab = '1'; |
| 206 | $default_gird_column_mobile = '1'; |
| 207 | } |
| 208 | |
| 209 | $gird_column_desktop = '0' !== $post_data['gird_column'] ? $post_data['gird_column'] : $default_gird_column_desktop; |
| 210 | $gird_column_tab = '0' !== $post_data['gird_column_tablet'] ? $post_data['gird_column_tablet'] : $default_gird_column_tab; |
| 211 | $gird_column_mobile = '0' !== $post_data['gird_column_mobile'] ? $post_data['gird_column_mobile'] : $default_gird_column_mobile; |
| 212 | |
| 213 | if ( in_array( $_layout, [ 'slider-layout10', 'slider-layout11' ] ) ) { |
| 214 | $gird_column_desktop = $gird_column_tab = $gird_column_mobile = '1'; |
| 215 | } |
| 216 | |
| 217 | ?> |
| 218 | <div class="rt-container-fluid rt-tpg-container tpg-el-main-wrapper slider-layout-main loading <?php echo esc_attr( $_layout . '-main' ); ?>" |
| 219 | id="<?php echo esc_attr( $layoutID ); ?>" |
| 220 | data-layout="<?php echo esc_attr( $data[ $_prefix . '_layout' ] ); ?>" |
| 221 | data-grid-style="" |
| 222 | data-desktop-col="<?php echo esc_attr( $gird_column_desktop ); ?>" |
| 223 | data-tab-col="<?php echo esc_attr( $gird_column_tab ); ?>" |
| 224 | data-mobile-col="<?php echo esc_attr( $gird_column_mobile ); ?>" |
| 225 | data-sc-id="elementor" |
| 226 | data-el-query='' |
| 227 | > |
| 228 | <?php |
| 229 | |
| 230 | $wrapper_class = []; |
| 231 | $wrapper_class[] = 'rt-content-loader grid-behaviour'; |
| 232 | |
| 233 | if ( $_layout == 'slider-layout1' ) { |
| 234 | $wrapper_class[] = 'grid-layout1 '; |
| 235 | } elseif ( $_layout == 'slider-layout2' ) { |
| 236 | $wrapper_class[] = 'grid-layout3'; |
| 237 | } elseif ( $_layout == 'slider-layout3' ) { |
| 238 | $wrapper_class[] = 'grid-layout4'; |
| 239 | } elseif ( $_layout == 'slider-layout4' ) { |
| 240 | $wrapper_class[] = 'grid-layout7'; |
| 241 | } elseif ( $_layout == 'slider-layout5' ) { |
| 242 | $wrapper_class[] = 'grid_hover-layout5 grid_hover-layout1 grid_hover_layout_wrapper'; |
| 243 | } elseif ( $_layout == 'slider-layout6' ) { |
| 244 | $wrapper_class[] = 'grid_hover-layout5 grid_hover-layout3 grid_hover_layout_wrapper'; |
| 245 | } elseif ( $_layout == 'slider-layout7' ) { |
| 246 | $wrapper_class[] = 'grid_hover-layout5 grid_hover_layout_wrapper'; |
| 247 | } elseif ( $_layout == 'slider-layout8' ) { |
| 248 | $wrapper_class[] = 'grid_hover-layout5 grid_hover-layout10 grid_hover_layout_wrapper'; |
| 249 | } elseif ( $_layout == 'slider-layout9' ) { |
| 250 | $wrapper_class[] = 'grid_hover-layout5 grid_hover-layout11 grid_hover_layout_wrapper'; |
| 251 | } elseif ( $_layout == 'slider-layout10' ) { |
| 252 | $wrapper_class[] = 'grid_hover-layout5 grid_hover-layout7 grid_hover_layout_wrapper'; |
| 253 | } elseif ( $_layout == 'slider-layout11' ) { |
| 254 | $wrapper_class[] = ' grid_hover-layout5 slider-layout'; |
| 255 | } elseif ( $_layout == 'slider-layout12' ) { |
| 256 | $wrapper_class[] = ' grid_hover-layout5 slider-layout'; |
| 257 | } |
| 258 | |
| 259 | $wrapper_class[] = $_prefix . '_layout_wrapper'; |
| 260 | |
| 261 | // section title settings. |
| 262 | $this->get_section_title( $data ); |
| 263 | |
| 264 | $slider_data = [ |
| 265 | 'speed' => $data['speed'], |
| 266 | 'autoPlayTimeOut' => $data['autoplaySpeed'], |
| 267 | 'autoPlay' => $data['autoplay'] == 'yes' ? true : false, |
| 268 | 'stopOnHover' => $data['stopOnHover'] == 'yes' ? true : false, |
| 269 | 'nav' => $data['arrows'] == 'yes' ? true : false, |
| 270 | 'dots' => $data['dots'] == 'yes' ? true : false, |
| 271 | 'loop' => $data['infinite'] == 'yes' ? true : false, |
| 272 | 'lazyLoad' => $data['lazyLoad'] == 'yes' ? true : false, |
| 273 | 'autoHeight' => $data['autoHeight'] == 'yes' ? true : false, |
| 274 | 'dynamic_dots' => $data['dynamic_dots'] == 'yes' ? true : false, |
| 275 | 'grabCursor' => $data['grabCursor'] == 'yes' ? true : false, |
| 276 | ]; |
| 277 | |
| 278 | if ( $data['enable_2_rows'] == 'yes' ) { |
| 279 | $slider_data['autoHeight'] = false; |
| 280 | } |
| 281 | ?> |
| 282 | |
| 283 | <div class="slider-main-wrapper <?php echo esc_attr( $_layout ); ?>"> |
| 284 | <div class="rt-swiper-holder swiper" |
| 285 | data-rtowl-options='<?php echo wp_json_encode( $slider_data ); ?>' |
| 286 | dir="<?php echo esc_attr( $data['slider_direction'] ); ?>" |
| 287 | > |
| 288 | <div class="swiper-wrapper <?php echo esc_attr( implode( ' ', $wrapper_class ) ); ?>"> |
| 289 | <?php |
| 290 | if ( $query->have_posts() ) { |
| 291 | $pCount = 1; |
| 292 | |
| 293 | while ( $query->have_posts() ) { |
| 294 | $query->the_post(); |
| 295 | set_query_var( 'tpg_post_count', $pCount ); |
| 296 | set_query_var( 'tpg_total_posts', $query->post_count ); |
| 297 | $this->tpg_template( $post_data ); |
| 298 | |
| 299 | if ( $_layout == 'slider-layout10' && $pCount == 5 ) { |
| 300 | $pCount = 0; |
| 301 | } |
| 302 | |
| 303 | $pCount ++; |
| 304 | } |
| 305 | } else { |
| 306 | if ( $data['no_posts_found_text'] ) { |
| 307 | printf( "<div class='no_posts_found_text'>%s</div>", esc_html( $data['no_posts_found_text'] ) ); |
| 308 | } else { |
| 309 | printf( "<div class='no_posts_found_text'>%s</div>", esc_html__( 'No post found', 'the-post-grid' ) ); |
| 310 | } |
| 311 | } |
| 312 | wp_reset_postdata(); |
| 313 | ?> |
| 314 | </div> |
| 315 | |
| 316 | </div> |
| 317 | |
| 318 | |
| 319 | <?php if ( ! in_array( $_layout, [ 'slider-layout11', 'slider-layout12' ] ) ) : ?> |
| 320 | <!--swiper-pagination-horizontal--> |
| 321 | <?php if ( $data['dots'] == 'yes' ) : ?> |
| 322 | <div class="swiper-pagination"></div> |
| 323 | <?php endif; ?> |
| 324 | |
| 325 | <?php if ( $data['arrows'] == 'yes' ) : ?> |
| 326 | <div class="swiper-navigation"> |
| 327 | <div class="slider-btn swiper-button-prev"></div> |
| 328 | <div class="slider-btn swiper-button-next"></div> |
| 329 | </div> |
| 330 | <?php endif; ?> |
| 331 | <?php endif; ?> |
| 332 | |
| 333 | <?php if ( in_array( $_layout, [ 'slider-layout11', 'slider-layout12' ] ) ) : ?> |
| 334 | <div class="slider-thumb-main-wrapper"> |
| 335 | <div class="swiper-thumb-wrapper gallery-thumbs swiper"> |
| 336 | <div class="swiper-wrapper"> |
| 337 | <?php |
| 338 | if ( $query->have_posts() ) { |
| 339 | $pCount = 1; |
| 340 | while ( $query->have_posts() ) { |
| 341 | $query->the_post(); |
| 342 | set_query_var( 'tpg_post_count', $pCount ); |
| 343 | set_query_var( 'tpg_total_posts', $query->post_count ); |
| 344 | ?> |
| 345 | <div class="swiper-slide"> |
| 346 | <div class="post-thumbnail-wrap"> |
| 347 | <div class="p-thumbnail"> |
| 348 | <?php echo get_the_post_thumbnail( get_the_ID(), 'thumbnail' ); ?> |
| 349 | </div> |
| 350 | <div class="p-content"> |
| 351 | <div class="post-taxonomy"> |
| 352 | <?php |
| 353 | $_cat_id = $data['post_type'] . '_taxonomy'; |
| 354 | echo get_the_term_list( get_the_ID(), $data[ $_cat_id ], null, '<span class="rt-separator">,</span>' ); |
| 355 | ?> |
| 356 | </div> |
| 357 | <h3 class="thumb-title"><?php echo get_the_title(); ?></h3> |
| 358 | <span class="thumb-date"><?php echo get_the_date(); ?></span> |
| 359 | </div> |
| 360 | </div> |
| 361 | </div> |
| 362 | <?php |
| 363 | $pCount ++; |
| 364 | } |
| 365 | } else { |
| 366 | if ( $data['no_posts_found_text'] ) { |
| 367 | printf( "<div class='no_posts_found_text'>%s</div>", esc_html( $data['no_posts_found_text'] ) ); |
| 368 | } else { |
| 369 | printf( "<div class='no_posts_found_text'>%s</div>", esc_html__( 'No post found', 'the-post-grid' ) ); |
| 370 | } |
| 371 | } |
| 372 | wp_reset_postdata(); |
| 373 | ?> |
| 374 | </div> |
| 375 | <div class="swiper-thumb-pagination"></div> |
| 376 | </div> |
| 377 | </div> |
| 378 | <?php endif; ?> |
| 379 | </div> |
| 380 | </div> |
| 381 | <?php |
| 382 | do_action( 'tpg_elementor_script' ); |
| 383 | } |
| 384 | } |
| 385 |