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
related-post.php
390 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Related Post 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 | * Related Post Class |
| 17 | */ |
| 18 | class TPGRelatedPost 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 - Related Post', 'the-post-grid' ); |
| 33 | $this->tpg_base = 'tpg-related-post'; |
| 34 | $this->tpg_icon = 'eicon-posts-grid tpg-grid-icon'; // .tpg-grid-icon class for just style |
| 35 | $this->tpg_category = $this->tpg_archive_category; |
| 36 | } |
| 37 | |
| 38 | public function get_script_depends() { |
| 39 | $scripts = []; |
| 40 | array_push( $scripts, 'imagesloaded' ); |
| 41 | array_push( $scripts, 'swiper' ); |
| 42 | array_push( $scripts, 'rt-tpg' ); |
| 43 | array_push( $scripts, 'rttpg-block-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-flaticon' ); |
| 55 | array_push( $style, 'rt-tpg-block' ); |
| 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, 'single' ); |
| 69 | |
| 70 | // Query. |
| 71 | rtTPGElementorHelper::query_builder( $this, 'single' ); |
| 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, 'single' ); |
| 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, 'single' ); |
| 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 | // ACF Style. |
| 129 | rtTPGElementorHelper::tpg_acf_style( $this ); |
| 130 | |
| 131 | // Social Style. |
| 132 | rtTPGElementorHelper::socialShareStyle( $this ); |
| 133 | |
| 134 | // Read more style. |
| 135 | rtTPGElementorHelper::readmoreStyle( $this ); |
| 136 | |
| 137 | // Slider Style. |
| 138 | rtTPGElementorHelper::slider_style( $this, 'single' ); |
| 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 | $data['post_type'] = 'post'; |
| 154 | $data['last_post_id'] = $this->last_post_id; |
| 155 | $_prefix = $this->prefix; |
| 156 | $enable_related_slider = $data['enable_related_slider']; |
| 157 | |
| 158 | if ( $data['enable_related_slider'] !== 'yes' ) { |
| 159 | $column_arr = [ '_column', '_column_tablet', '_column_mobile' ]; |
| 160 | foreach ( $column_arr as $device ) { |
| 161 | if ( ! ( isset( $data[ 'slider' . $device ] ) && $data[ 'slider' . $device ] ) ) { |
| 162 | continue; |
| 163 | } |
| 164 | if ( $data[ 'slider' . $device ] == '1' ) { |
| 165 | $data[ 'slider' . $device ] = '12'; |
| 166 | } elseif ( $data[ 'slider' . $device ] == '2' ) { |
| 167 | $data[ 'slider' . $device ] = '6'; |
| 168 | } elseif ( $data[ 'slider' . $device ] == '3' ) { |
| 169 | $data[ 'slider' . $device ] = '4'; |
| 170 | } elseif ( $data[ 'slider' . $device ] == '4' ) { |
| 171 | $data[ 'slider' . $device ] = '3'; |
| 172 | } elseif ( $data[ 'slider' . $device ] == '5' ) { |
| 173 | $data[ 'slider' . $device ] = '24'; |
| 174 | } elseif ( $data[ 'slider' . $device ] == '6' ) { |
| 175 | $data[ 'slider' . $device ] = '2'; |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | if ( ! rtTPG()->hasPro() ) { ?> |
| 181 | <h3 style="text-align: center"><?php echo esc_html__( 'Please upgrade to pro for slider layout!', 'the-post-grid' ); ?></h3> |
| 182 | <?php |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | if ( rtTPG()->hasPro() && ( 'popup' == $data['post_link_type'] || 'multi_popup' == $data['post_link_type'] ) ) { |
| 187 | wp_enqueue_style( 'rt-magnific-popup' ); |
| 188 | wp_enqueue_script( 'rt-scrollbar' ); |
| 189 | wp_enqueue_script( 'rt-magnific-popup' ); |
| 190 | add_action( 'wp_footer', [ Fns::class, 'get_modal_markup' ], 1 ); |
| 191 | } |
| 192 | |
| 193 | // if ( 'show' == $data['show_pagination'] && 'pagination_ajax' == $data['pagination_type'] ) { |
| 194 | // wp_enqueue_script( 'rt-pagination' ); |
| 195 | // } |
| 196 | |
| 197 | // Query. |
| 198 | $query_args = rtTPGElementorQuery::post_query_builder( $data, $_prefix, 'single' ); |
| 199 | $query = new WP_Query( $query_args ); |
| 200 | $rand = wp_rand(); |
| 201 | $layoutID = 'rt-tpg-container-' . $rand; |
| 202 | $posts_per_page = $data['post_limit']; |
| 203 | |
| 204 | /** |
| 205 | * TODO: Get Post Data for render post |
| 206 | */ |
| 207 | $post_data = Fns::get_render_data_set( $data, $query->max_num_pages, $posts_per_page, $_prefix ); |
| 208 | $_layout = $data[ $_prefix . '_layout' ]; |
| 209 | |
| 210 | $post_data['lazy_load'] = $data['lazyLoad']; |
| 211 | |
| 212 | /** |
| 213 | * Post type render |
| 214 | */ |
| 215 | $post_types = Fns::get_post_types(); |
| 216 | foreach ( $post_types as $post_type => $label ) { |
| 217 | $_taxonomies = get_object_taxonomies( $post_type, 'object' ); |
| 218 | |
| 219 | if ( empty( $_taxonomies ) ) { |
| 220 | continue; |
| 221 | } |
| 222 | |
| 223 | $post_data[ $data['post_type'] . '_taxonomy' ] = isset( $data[ $data['post_type'] . '_taxonomy' ] ) ? $data[ $data['post_type'] . '_taxonomy' ] : ''; |
| 224 | $post_data[ $data['post_type'] . '_tags' ] = isset( $data[ $data['post_type'] . '_tags' ] ) ? $data[ $data['post_type'] . '_tags' ] : ''; |
| 225 | } |
| 226 | |
| 227 | $post_data['enable_2_rows'] = false; |
| 228 | |
| 229 | $default_grid_column_desktop = $enable_related_slider ? '3' : '4'; |
| 230 | $default_grid_column_tab = $enable_related_slider ? '2' : '6'; |
| 231 | $default_grid_column_mobile = $enable_related_slider ? '1' : '12'; |
| 232 | |
| 233 | $grid_column_desktop = '0' !== $post_data['grid_column'] ? $post_data['grid_column'] : $default_grid_column_desktop; |
| 234 | $grid_column_tab = '0' !== $post_data['grid_column_tablet'] ? $post_data['grid_column_tablet'] : $default_grid_column_tab; |
| 235 | $grid_column_mobile = '0' !== $post_data['grid_column_mobile'] ? $post_data['grid_column_mobile'] : $default_grid_column_mobile; |
| 236 | |
| 237 | |
| 238 | $item_column = "rt-col-md-{$grid_column_desktop} rt-col-sm-{$grid_column_tab} rt-col-xs-{$grid_column_mobile}"; |
| 239 | |
| 240 | $slider_main_class = $enable_related_slider ? 'slider-layout-main loading' : 'slider-is-disable'; |
| 241 | |
| 242 | if ( $query->have_posts() ) : |
| 243 | ?> |
| 244 | <div class="rt-container-fluid rt-tpg-container tpg-el-main-wrapper <?php echo esc_attr( $_layout . '-main' . ' ' . $slider_main_class ); ?>" |
| 245 | id="<?php echo esc_attr( $layoutID ); ?>" |
| 246 | data-layout="<?php echo esc_attr( $data[ $_prefix . '_layout' ] ); ?>" |
| 247 | data-grid-style="" |
| 248 | data-desktop-col="<?php echo esc_attr( $grid_column_desktop ); ?>" |
| 249 | data-tab-col="<?php echo esc_attr( $grid_column_tab ); ?>" |
| 250 | data-mobile-col="<?php echo esc_attr( $grid_column_mobile ); ?>" |
| 251 | data-sc-id="elementor" |
| 252 | data-el-query='' |
| 253 | > |
| 254 | <?php |
| 255 | $settings = get_option( rtTPG()->options['settings'] ); |
| 256 | if ( isset( $settings['tpg_load_script'] ) && isset( $settings['tpg_enable_preloader'] ) ) { |
| 257 | ?> |
| 258 | <div id="bottom-script-loader" class="bottom-script-loader"> |
| 259 | <div class="rt-ball-clip-rotate"> |
| 260 | <div></div> |
| 261 | </div> |
| 262 | </div> |
| 263 | <?php |
| 264 | } |
| 265 | |
| 266 | $wrapper_class = []; |
| 267 | $wrapper_class[] = 'rt-content-loader grid-behaviour'; |
| 268 | |
| 269 | if ( $_layout == 'slider-layout1' ) { |
| 270 | $wrapper_class[] = 'grid-layout1 '; |
| 271 | } elseif ( $_layout == 'slider-layout2' ) { |
| 272 | $wrapper_class[] = 'grid-layout3'; |
| 273 | } elseif ( $_layout == 'slider-layout3' ) { |
| 274 | $wrapper_class[] = 'grid-layout4'; |
| 275 | } elseif ( $_layout == 'slider-layout4' ) { |
| 276 | $wrapper_class[] = 'grid-layout7'; |
| 277 | } elseif ( $_layout == 'slider-layout5' ) { |
| 278 | $wrapper_class[] = 'grid_hover-layout5 grid_hover-layout1 grid_hover_layout_wrapper'; |
| 279 | } elseif ( $_layout == 'slider-layout6' ) { |
| 280 | $wrapper_class[] = 'grid_hover-layout5 grid_hover-layout3 grid_hover_layout_wrapper'; |
| 281 | } elseif ( $_layout == 'slider-layout7' ) { |
| 282 | $wrapper_class[] = 'grid_hover-layout5 grid_hover_layout_wrapper'; |
| 283 | } elseif ( $_layout == 'slider-layout8' ) { |
| 284 | $wrapper_class[] = 'grid_hover-layout5 grid_hover-layout10 grid_hover_layout_wrapper'; |
| 285 | } elseif ( $_layout == 'slider-layout9' ) { |
| 286 | $wrapper_class[] = 'grid_hover-layout5 grid_hover-layout11 grid_hover_layout_wrapper'; |
| 287 | } elseif ( $_layout == 'slider-layout10' ) { |
| 288 | $wrapper_class[] = 'grid_hover-layout5 grid_hover-layout7 grid_hover_layout_wrapper'; |
| 289 | } elseif ( $_layout == 'slider-layout11' ) { |
| 290 | $wrapper_class[] = ' grid_hover-layout5 slider-layout'; |
| 291 | } elseif ( $_layout == 'slider-layout12' ) { |
| 292 | $wrapper_class[] = ' grid_hover-layout5 slider-layout'; |
| 293 | } |
| 294 | |
| 295 | $wrapper_class[] = $_prefix . '_layout_wrapper'; |
| 296 | |
| 297 | //section title settings |
| 298 | Fns::get_section_title( $data ); |
| 299 | |
| 300 | $slider_data = [ |
| 301 | 'speed' => $data['speed'], |
| 302 | 'autoPlayTimeOut' => $data['autoplaySpeed'], |
| 303 | 'autoPlay' => $data['autoplay'] == 'yes' ? true : false, |
| 304 | 'stopOnHover' => $data['stopOnHover'] == 'yes' ? true : false, |
| 305 | 'nav' => $data['arrows'] == 'yes' ? true : false, |
| 306 | 'dots' => $data['dots'] == 'yes' ? true : false, |
| 307 | 'loop' => $data['infinite'] == 'yes' ? true : false, |
| 308 | 'lazyLoad' => $data['lazyLoad'] == 'yes' ? true : false, |
| 309 | 'autoHeight' => $data['autoHeight'] == 'yes' ? true : false, |
| 310 | ]; |
| 311 | |
| 312 | if ( $data['enable_2_rows'] == 'yes' ) { |
| 313 | $slider_data['autoHeight'] = false; |
| 314 | } |
| 315 | |
| 316 | $col_start_class = $col_end_class = null; |
| 317 | ?> |
| 318 | |
| 319 | <?php if ( $enable_related_slider ) { ?> |
| 320 | <div class="slider-main-wrapper <?php echo esc_attr( $_layout ); ?>"> |
| 321 | |
| 322 | <div class="rt-swiper-holder swiper" |
| 323 | data-rtowl-options='<?php echo wp_json_encode( $slider_data ); ?>' |
| 324 | dir="<?php echo esc_attr( $data['slider_direction'] ); ?>"> |
| 325 | <div class="swiper-wrapper <?php echo esc_attr( implode( ' ', $wrapper_class ) ); ?>"> |
| 326 | <?php } else { ?> |
| 327 | <div class="rt-row rt-content-loader <?php echo esc_attr( implode( ' ', $wrapper_class ) ); ?>"> |
| 328 | <?php |
| 329 | } |
| 330 | ?> |
| 331 | |
| 332 | <?php |
| 333 | $pCount = 1; |
| 334 | |
| 335 | while ( $query->have_posts() ) { |
| 336 | $query->the_post(); |
| 337 | set_query_var( 'tpg_post_count', $pCount ); |
| 338 | set_query_var( 'tpg_total_posts', $query->post_count ); |
| 339 | ?> |
| 340 | <?php if ( ! $enable_related_slider ) { ?> |
| 341 | <div class='<?php echo esc_attr( $item_column ); ?>'> |
| 342 | <?php } ?> |
| 343 | <?php |
| 344 | Fns::tpg_template( $post_data ); |
| 345 | ?> |
| 346 | <?php if ( ! $enable_related_slider ) { ?> |
| 347 | </div> |
| 348 | <?php } ?> |
| 349 | <?php |
| 350 | |
| 351 | if ( $_layout == 'slider-layout10' && $pCount == 5 ) { |
| 352 | $pCount = 0; |
| 353 | } |
| 354 | |
| 355 | $pCount ++; |
| 356 | } |
| 357 | wp_reset_postdata(); |
| 358 | ?> |
| 359 | |
| 360 | |
| 361 | <?php if ( $enable_related_slider ) { ?> |
| 362 | </div> |
| 363 | |
| 364 | </div> |
| 365 | |
| 366 | |
| 367 | <!--swiper-pagination-horizontal--> |
| 368 | <?php if ( $data['dots'] == 'yes' ) : ?> |
| 369 | <div class="swiper-pagination"></div> |
| 370 | <?php endif; ?> |
| 371 | |
| 372 | <?php if ( $data['arrows'] == 'yes' ) : ?> |
| 373 | <div class="swiper-navigation"> |
| 374 | <div class="slider-btn swiper-button-prev"></div> |
| 375 | <div class="slider-btn swiper-button-next"></div> |
| 376 | </div> |
| 377 | <?php endif; ?> |
| 378 | |
| 379 | |
| 380 | <?php } ?> |
| 381 | </div> |
| 382 | </div> |
| 383 | <?php |
| 384 | endif; |
| 385 | |
| 386 | do_action( 'tpg_elementor_script' ); |
| 387 | } |
| 388 | |
| 389 | } |
| 390 |