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
related-post.php
388 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, '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 | } |
| 56 | |
| 57 | return $style; |
| 58 | } |
| 59 | |
| 60 | protected function register_controls() { |
| 61 | /** |
| 62 | * Content Tabs |
| 63 | * ============= |
| 64 | */ |
| 65 | |
| 66 | // Layout. |
| 67 | rtTPGElementorHelper::grid_layouts( $this, 'single' ); |
| 68 | |
| 69 | // Query. |
| 70 | rtTPGElementorHelper::query_builder( $this, 'single' ); |
| 71 | |
| 72 | // Links. |
| 73 | rtTPGElementorHelper::links( $this ); |
| 74 | |
| 75 | /** |
| 76 | * Settings Tabs |
| 77 | * ============= |
| 78 | */ |
| 79 | |
| 80 | // Field Selection. |
| 81 | rtTPGElementorHelper::field_selection( $this ); |
| 82 | |
| 83 | // Section Title Settings. |
| 84 | rtTPGElementorHelper::section_title_settings( $this, 'single' ); |
| 85 | |
| 86 | // Title Settings. |
| 87 | rtTPGElementorHelper::post_title_settings( $this ); |
| 88 | |
| 89 | // Thumbnail Settings. |
| 90 | rtTPGElementorHelper::post_thumbnail_settings( $this ); |
| 91 | |
| 92 | // Excerpt Settings. |
| 93 | rtTPGElementorHelper::post_excerpt_settings( $this ); |
| 94 | |
| 95 | // Meta Settings. |
| 96 | rtTPGElementorHelper::post_meta_settings( $this ); |
| 97 | |
| 98 | // Advanced Custom Field ACF Settings. |
| 99 | rtTPGElementorHelper::tpg_acf_settings( $this ); |
| 100 | |
| 101 | // Readmore Settings. |
| 102 | rtTPGElementorHelper::post_readmore_settings( $this ); |
| 103 | |
| 104 | // Slider Settings. |
| 105 | rtTPGElementorHelper::slider_settings( $this, 'single' ); |
| 106 | |
| 107 | /** |
| 108 | * Style Tabs |
| 109 | * ============= |
| 110 | */ |
| 111 | |
| 112 | // Section Title. |
| 113 | rtTPGElementorHelper::sectionTitle( $this ); |
| 114 | |
| 115 | // Title Style. |
| 116 | rtTPGElementorHelper::titleStyle( $this ); |
| 117 | |
| 118 | // Thumbnail Style. |
| 119 | rtTPGElementorHelper::thumbnailStyle( $this ); |
| 120 | |
| 121 | // Content Style. |
| 122 | rtTPGElementorHelper::contentStyle( $this ); |
| 123 | |
| 124 | // Meta Info Style. |
| 125 | rtTPGElementorHelper::metaInfoStyle( $this ); |
| 126 | |
| 127 | // ACF Style. |
| 128 | rtTPGElementorHelper::tpg_acf_style( $this ); |
| 129 | |
| 130 | // Social Style. |
| 131 | rtTPGElementorHelper::socialShareStyle( $this ); |
| 132 | |
| 133 | // Read more style. |
| 134 | rtTPGElementorHelper::readmoreStyle( $this ); |
| 135 | |
| 136 | // Slider Style. |
| 137 | rtTPGElementorHelper::slider_style( $this, 'single' ); |
| 138 | rtTPGElementorHelper::slider_thumb_style( $this ); |
| 139 | |
| 140 | // Link Style. |
| 141 | rtTPGElementorHelper::linkStyle( $this ); |
| 142 | |
| 143 | // Box Settings. |
| 144 | rtTPGElementorHelper::articlBoxSettings( $this ); |
| 145 | |
| 146 | // Promotions. |
| 147 | rtTPGElementorHelper::promotions( $this ); |
| 148 | } |
| 149 | |
| 150 | protected function render() { |
| 151 | $data = $this->get_settings(); |
| 152 | $data['post_type'] = 'post'; |
| 153 | $data['last_post_id'] = $this->last_post_id; |
| 154 | $_prefix = $this->prefix; |
| 155 | $enable_related_slider = $data['enable_related_slider']; |
| 156 | |
| 157 | if ( $data['enable_related_slider'] !== 'yes' ) { |
| 158 | $column_arr = [ '_column', '_column_tablet', '_column_mobile' ]; |
| 159 | foreach ( $column_arr as $device ) { |
| 160 | if ( ! ( isset( $data[ 'slider' . $device ] ) && $data[ 'slider' . $device ] ) ) { |
| 161 | continue; |
| 162 | } |
| 163 | if ( $data[ 'slider' . $device ] == '1' ) { |
| 164 | $data[ 'slider' . $device ] = '12'; |
| 165 | } elseif ( $data[ 'slider' . $device ] == '2' ) { |
| 166 | $data[ 'slider' . $device ] = '6'; |
| 167 | } elseif ( $data[ 'slider' . $device ] == '3' ) { |
| 168 | $data[ 'slider' . $device ] = '4'; |
| 169 | } elseif ( $data[ 'slider' . $device ] == '4' ) { |
| 170 | $data[ 'slider' . $device ] = '3'; |
| 171 | } elseif ( $data[ 'slider' . $device ] == '5' ) { |
| 172 | $data[ 'slider' . $device ] = '24'; |
| 173 | } elseif ( $data[ 'slider' . $device ] == '6' ) { |
| 174 | $data[ 'slider' . $device ] = '2'; |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | if ( ! rtTPG()->hasPro() ) { ?> |
| 180 | <h3 style="text-align: center"><?php echo esc_html__( 'Please upgrade to pro for slider layout!', 'the-post-grid' ); ?></h3> |
| 181 | <?php |
| 182 | return; |
| 183 | } |
| 184 | |
| 185 | if ( rtTPG()->hasPro() && ( 'popup' == $data['post_link_type'] || 'multi_popup' == $data['post_link_type'] ) ) { |
| 186 | wp_enqueue_style( 'rt-magnific-popup' ); |
| 187 | wp_enqueue_script( 'rt-scrollbar' ); |
| 188 | wp_enqueue_script( 'rt-magnific-popup' ); |
| 189 | add_action( 'wp_footer', [ $this, 'get_modal_markup' ], 1 ); |
| 190 | } |
| 191 | |
| 192 | // if ( 'show' == $data['show_pagination'] && 'pagination_ajax' == $data['pagination_type'] ) { |
| 193 | // wp_enqueue_script( 'rt-pagination' ); |
| 194 | // } |
| 195 | |
| 196 | // Query. |
| 197 | $query_args = rtTPGElementorQuery::post_query_builder( $data, $_prefix, 'single' ); |
| 198 | $query = new WP_Query( $query_args ); |
| 199 | $rand = wp_rand(); |
| 200 | $layoutID = 'rt-tpg-container-' . $rand; |
| 201 | $posts_per_page = $data['post_limit']; |
| 202 | |
| 203 | /** |
| 204 | * TODO: Get Post Data for render post |
| 205 | */ |
| 206 | $post_data = $this->get_render_data_set( $data, $query->max_num_pages, $posts_per_page ); |
| 207 | $_layout = $data[ $_prefix . '_layout' ]; |
| 208 | |
| 209 | $post_data['lazy_load'] = $data['lazyLoad']; |
| 210 | |
| 211 | /** |
| 212 | * Post type render |
| 213 | */ |
| 214 | $post_types = Fns::get_post_types(); |
| 215 | foreach ( $post_types as $post_type => $label ) { |
| 216 | $_taxonomies = get_object_taxonomies( $post_type, 'object' ); |
| 217 | |
| 218 | if ( empty( $_taxonomies ) ) { |
| 219 | continue; |
| 220 | } |
| 221 | |
| 222 | $post_data[ $data['post_type'] . '_taxonomy' ] = isset( $data[ $data['post_type'] . '_taxonomy' ] ) ? $data[ $data['post_type'] . '_taxonomy' ] : ''; |
| 223 | $post_data[ $data['post_type'] . '_tags' ] = isset( $data[ $data['post_type'] . '_tags' ] ) ? $data[ $data['post_type'] . '_tags' ] : ''; |
| 224 | } |
| 225 | |
| 226 | $post_data['enable_2_rows'] = false; |
| 227 | |
| 228 | $default_gird_column_desktop = $enable_related_slider ? '3' : '4'; |
| 229 | $default_gird_column_tab = $enable_related_slider ? '2' : '6'; |
| 230 | $default_gird_column_mobile = $enable_related_slider ? '1' : '12'; |
| 231 | |
| 232 | $gird_column_desktop = '0' !== $post_data['gird_column'] ? $post_data['gird_column'] : $default_gird_column_desktop; |
| 233 | $gird_column_tab = '0' !== $post_data['gird_column_tablet'] ? $post_data['gird_column_tablet'] : $default_gird_column_tab; |
| 234 | $gird_column_mobile = '0' !== $post_data['gird_column_mobile'] ? $post_data['gird_column_mobile'] : $default_gird_column_mobile; |
| 235 | |
| 236 | $item_column = "rt-col-md-{$gird_column_desktop} rt-col-sm-{$gird_column_tab} rt-col-xs-{$gird_column_mobile}"; |
| 237 | |
| 238 | $slider_main_class = $enable_related_slider ? 'slider-layout-main loading' : 'slider-is-disable'; |
| 239 | |
| 240 | if ( $query->have_posts() ) : |
| 241 | ?> |
| 242 | <div class="rt-container-fluid rt-tpg-container tpg-el-main-wrapper <?php echo esc_attr( $_layout . '-main' . ' ' . $slider_main_class ); ?>" |
| 243 | id="<?php echo esc_attr( $layoutID ); ?>" |
| 244 | data-layout="<?php echo esc_attr( $data[ $_prefix . '_layout' ] ); ?>" |
| 245 | data-grid-style="" |
| 246 | data-desktop-col="<?php echo esc_attr( $gird_column_desktop ); ?>" |
| 247 | data-tab-col="<?php echo esc_attr( $gird_column_tab ); ?>" |
| 248 | data-mobile-col="<?php echo esc_attr( $gird_column_mobile ); ?>" |
| 249 | data-sc-id="elementor" |
| 250 | data-el-query='' |
| 251 | > |
| 252 | <?php |
| 253 | $settings = get_option( rtTPG()->options['settings'] ); |
| 254 | if ( isset( $settings['tpg_load_script'] ) && isset( $settings['tpg_enable_preloader'] ) ) { |
| 255 | ?> |
| 256 | <div id="bottom-script-loader" class="bottom-script-loader"> |
| 257 | <div class="rt-ball-clip-rotate"> |
| 258 | <div></div> |
| 259 | </div> |
| 260 | </div> |
| 261 | <?php |
| 262 | } |
| 263 | |
| 264 | $wrapper_class = []; |
| 265 | $wrapper_class[] = 'rt-content-loader grid-behaviour'; |
| 266 | |
| 267 | if ( $_layout == 'slider-layout1' ) { |
| 268 | $wrapper_class[] = 'grid-layout1 '; |
| 269 | } elseif ( $_layout == 'slider-layout2' ) { |
| 270 | $wrapper_class[] = 'grid-layout3'; |
| 271 | } elseif ( $_layout == 'slider-layout3' ) { |
| 272 | $wrapper_class[] = 'grid-layout4'; |
| 273 | } elseif ( $_layout == 'slider-layout4' ) { |
| 274 | $wrapper_class[] = 'grid-layout7'; |
| 275 | } elseif ( $_layout == 'slider-layout5' ) { |
| 276 | $wrapper_class[] = 'grid_hover-layout5 grid_hover-layout1 grid_hover_layout_wrapper'; |
| 277 | } elseif ( $_layout == 'slider-layout6' ) { |
| 278 | $wrapper_class[] = 'grid_hover-layout5 grid_hover-layout3 grid_hover_layout_wrapper'; |
| 279 | } elseif ( $_layout == 'slider-layout7' ) { |
| 280 | $wrapper_class[] = 'grid_hover-layout5 grid_hover_layout_wrapper'; |
| 281 | } elseif ( $_layout == 'slider-layout8' ) { |
| 282 | $wrapper_class[] = 'grid_hover-layout5 grid_hover-layout10 grid_hover_layout_wrapper'; |
| 283 | } elseif ( $_layout == 'slider-layout9' ) { |
| 284 | $wrapper_class[] = 'grid_hover-layout5 grid_hover-layout11 grid_hover_layout_wrapper'; |
| 285 | } elseif ( $_layout == 'slider-layout10' ) { |
| 286 | $wrapper_class[] = 'grid_hover-layout5 grid_hover-layout7 grid_hover_layout_wrapper'; |
| 287 | } elseif ( $_layout == 'slider-layout11' ) { |
| 288 | $wrapper_class[] = ' grid_hover-layout5 slider-layout'; |
| 289 | } elseif ( $_layout == 'slider-layout12' ) { |
| 290 | $wrapper_class[] = ' grid_hover-layout5 slider-layout'; |
| 291 | } |
| 292 | |
| 293 | $wrapper_class[] = $_prefix . '_layout_wrapper'; |
| 294 | |
| 295 | // section title settings. |
| 296 | $this->get_section_title( $data ); |
| 297 | |
| 298 | $slider_data = [ |
| 299 | 'speed' => $data['speed'], |
| 300 | 'autoPlayTimeOut' => $data['autoplaySpeed'], |
| 301 | 'autoPlay' => $data['autoplay'] == 'yes' ? true : false, |
| 302 | 'stopOnHover' => $data['stopOnHover'] == 'yes' ? true : false, |
| 303 | 'nav' => $data['arrows'] == 'yes' ? true : false, |
| 304 | 'dots' => $data['dots'] == 'yes' ? true : false, |
| 305 | 'loop' => $data['infinite'] == 'yes' ? true : false, |
| 306 | 'lazyLoad' => $data['lazyLoad'] == 'yes' ? true : false, |
| 307 | 'autoHeight' => $data['autoHeight'] == 'yes' ? true : false, |
| 308 | ]; |
| 309 | |
| 310 | if ( $data['enable_2_rows'] == 'yes' ) { |
| 311 | $slider_data['autoHeight'] = false; |
| 312 | } |
| 313 | |
| 314 | $col_start_class = $col_end_class = null; |
| 315 | ?> |
| 316 | |
| 317 | <?php if ( $enable_related_slider ) { ?> |
| 318 | <div class="slider-main-wrapper <?php echo esc_attr( $_layout ); ?>"> |
| 319 | |
| 320 | <div class="rt-swiper-holder swiper" |
| 321 | data-rtowl-options='<?php echo wp_json_encode( $slider_data ); ?>' |
| 322 | dir="<?php echo esc_attr( $data['slider_direction'] ); ?>"> |
| 323 | <div class="swiper-wrapper <?php echo esc_attr( implode( ' ', $wrapper_class ) ); ?>"> |
| 324 | <?php } else { ?> |
| 325 | <div class="rt-row rt-content-loader <?php echo esc_attr( implode( ' ', $wrapper_class ) ); ?>"> |
| 326 | <?php |
| 327 | } |
| 328 | ?> |
| 329 | |
| 330 | <?php |
| 331 | $pCount = 1; |
| 332 | |
| 333 | while ( $query->have_posts() ) { |
| 334 | $query->the_post(); |
| 335 | set_query_var( 'tpg_post_count', $pCount ); |
| 336 | set_query_var( 'tpg_total_posts', $query->post_count ); |
| 337 | ?> |
| 338 | <?php if ( ! $enable_related_slider ) { ?> |
| 339 | <div class='<?php echo esc_attr( $item_column ); ?>'> |
| 340 | <?php } ?> |
| 341 | <?php |
| 342 | $this->tpg_template( $post_data ); |
| 343 | ?> |
| 344 | <?php if ( ! $enable_related_slider ) { ?> |
| 345 | </div> |
| 346 | <?php } ?> |
| 347 | <?php |
| 348 | |
| 349 | if ( $_layout == 'slider-layout10' && $pCount == 5 ) { |
| 350 | $pCount = 0; |
| 351 | } |
| 352 | |
| 353 | $pCount ++; |
| 354 | } |
| 355 | wp_reset_postdata(); |
| 356 | ?> |
| 357 | |
| 358 | |
| 359 | <?php if ( $enable_related_slider ) { ?> |
| 360 | </div> |
| 361 | |
| 362 | </div> |
| 363 | |
| 364 | |
| 365 | <!--swiper-pagination-horizontal--> |
| 366 | <?php if ( $data['dots'] == 'yes' ) : ?> |
| 367 | <div class="swiper-pagination"></div> |
| 368 | <?php endif; ?> |
| 369 | |
| 370 | <?php if ( $data['arrows'] == 'yes' ) : ?> |
| 371 | <div class="swiper-navigation"> |
| 372 | <div class="slider-btn swiper-button-prev"></div> |
| 373 | <div class="slider-btn swiper-button-next"></div> |
| 374 | </div> |
| 375 | <?php endif; ?> |
| 376 | |
| 377 | |
| 378 | <?php } ?> |
| 379 | </div> |
| 380 | </div> |
| 381 | <?php |
| 382 | endif; |
| 383 | |
| 384 | do_action( 'tpg_elementor_script' ); |
| 385 | } |
| 386 | |
| 387 | } |
| 388 |