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
grid-layout-archive.php
278 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Grid Layout Archive 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 | * Grid Layout Archive Class |
| 17 | */ |
| 18 | class TPGGridLayoutArchive 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 = 'grid'; |
| 32 | $this->tpg_name = esc_html__( 'TPG - Grid Layout Archive', 'the-post-grid' ); |
| 33 | $this->tpg_base = 'tpg-grid-layout-archive'; |
| 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, 'rt-tpg' ); |
| 42 | array_push( $scripts, 'rt-tpg-el-pro' ); |
| 43 | |
| 44 | return $scripts; |
| 45 | } |
| 46 | |
| 47 | public function get_style_depends() { |
| 48 | $settings = get_option( rtTPG()->options['settings'] ); |
| 49 | $style = []; |
| 50 | |
| 51 | if ( isset( $settings['tpg_load_script'] ) ) { |
| 52 | array_push( $style, 'rt-fontawsome' ); |
| 53 | array_push( $style, 'rt-tpg-elementor' ); |
| 54 | } |
| 55 | |
| 56 | return $style; |
| 57 | } |
| 58 | |
| 59 | protected function register_controls() { |
| 60 | /** Content TAB */ |
| 61 | |
| 62 | // Layout. |
| 63 | rtTPGElementorHelper::grid_layouts( $this, 'archive' ); |
| 64 | |
| 65 | // Query. |
| 66 | rtTPGElementorHelper::query_builder( $this ); |
| 67 | |
| 68 | // Filter Settings. |
| 69 | // rtTPGElementorHelper::filter_settings( $this, 'archive' ); |
| 70 | |
| 71 | // Pagination Settings. |
| 72 | rtTPGElementorHelper::pagination_settings( $this, 'archive' ); |
| 73 | |
| 74 | // Links. |
| 75 | rtTPGElementorHelper::links( $this ); |
| 76 | |
| 77 | /** |
| 78 | * Settings Tab |
| 79 | * =========== |
| 80 | */ |
| 81 | |
| 82 | // Field Selection. |
| 83 | rtTPGElementorHelper::field_selection( $this ); |
| 84 | |
| 85 | // Section Title Settings. |
| 86 | rtTPGElementorHelper::section_title_settings( $this, 'archive' ); |
| 87 | |
| 88 | // Title Settings. |
| 89 | rtTPGElementorHelper::post_title_settings( $this ); |
| 90 | |
| 91 | // Thumbnail Settings. |
| 92 | rtTPGElementorHelper::post_thumbnail_settings( $this ); |
| 93 | |
| 94 | // Excerpt Settings. |
| 95 | rtTPGElementorHelper::post_excerpt_settings( $this ); |
| 96 | |
| 97 | // Meta Settings. |
| 98 | rtTPGElementorHelper::post_meta_settings( $this ); |
| 99 | |
| 100 | // Advanced Custom Field ACF Settings. |
| 101 | rtTPGElementorHelper::tpg_acf_settings( $this ); |
| 102 | |
| 103 | // Readmore Settings. |
| 104 | rtTPGElementorHelper::post_readmore_settings( $this ); |
| 105 | |
| 106 | /** Style TAB */ |
| 107 | |
| 108 | // Section Title Style. |
| 109 | rtTPGElementorHelper::sectionTitle( $this, 'archive' ); |
| 110 | |
| 111 | // Title Style. |
| 112 | rtTPGElementorHelper::titleStyle( $this ); |
| 113 | |
| 114 | // Thumbnail Style. |
| 115 | rtTPGElementorHelper::thumbnailStyle( $this ); |
| 116 | |
| 117 | // Content Style. |
| 118 | rtTPGElementorHelper::contentStyle( $this ); |
| 119 | |
| 120 | // Meta Info Style. |
| 121 | rtTPGElementorHelper::metaInfoStyle( $this ); |
| 122 | |
| 123 | // Social Share Settings. |
| 124 | rtTPGElementorHelper::socialShareStyle( $this ); |
| 125 | |
| 126 | // ACF Style. |
| 127 | rtTPGElementorHelper::tpg_acf_style( $this ); |
| 128 | |
| 129 | // Read More Style. |
| 130 | rtTPGElementorHelper::readmoreStyle( $this ); |
| 131 | |
| 132 | // Link Style. |
| 133 | rtTPGElementorHelper::linkStyle( $this ); |
| 134 | |
| 135 | // Pagination - Loadmore Style. |
| 136 | rtTPGElementorHelper::paginationStyle( $this ); |
| 137 | |
| 138 | // Box Settings. |
| 139 | rtTPGElementorHelper::articlBoxSettings( $this ); |
| 140 | |
| 141 | // Promotions. |
| 142 | rtTPGElementorHelper::promotions( $this ); |
| 143 | } |
| 144 | |
| 145 | protected function render() { |
| 146 | $data = $this->get_settings(); |
| 147 | $_prefix = $this->prefix; |
| 148 | $data['post_type'] = 'post'; |
| 149 | |
| 150 | if ( ! rtTPG()->hasPro() && ! in_array( $data[ $_prefix . '_layout' ], [ 'grid-layout1', 'grid-layout2' ] ) ) { |
| 151 | $data[ $_prefix . '_layout' ] = 'grid-layout1'; |
| 152 | } |
| 153 | |
| 154 | if ( rtTPG()->hasPro() && ( 'popup' == $data['post_link_type'] || 'multi_popup' == $data['post_link_type'] ) ) { |
| 155 | wp_enqueue_style( 'rt-magnific-popup' ); |
| 156 | wp_enqueue_script( 'rt-scrollbar' ); |
| 157 | wp_enqueue_script( 'rt-magnific-popup' ); |
| 158 | add_action( 'wp_footer', [ $this, 'get_modal_markup' ] ); |
| 159 | } |
| 160 | |
| 161 | if ( 'masonry' === $data['grid_layout_style'] ) { |
| 162 | wp_enqueue_script( 'rt-isotope-js' ); |
| 163 | wp_enqueue_script( 'jquery-masonry' ); |
| 164 | } |
| 165 | |
| 166 | if ( 'show' == $data['show_pagination'] && 'pagination_ajax' == $data['pagination_type'] ) { |
| 167 | wp_enqueue_script( 'rt-pagination' ); |
| 168 | } |
| 169 | |
| 170 | // Query. |
| 171 | $query_args = rtTPGElementorQuery::post_query_builder( $data, $_prefix ); |
| 172 | $query = new WP_Query( $query_args ); |
| 173 | $rand = wp_rand(); |
| 174 | $layoutID = 'rt-tpg-container-' . $rand; |
| 175 | $posts_per_page = $data['post_limit']; |
| 176 | |
| 177 | /** |
| 178 | * TODO: Get Post Data for render post |
| 179 | */ |
| 180 | $post_data = $this->get_render_data_set( $data, $query->max_num_pages, $posts_per_page ); |
| 181 | |
| 182 | /** |
| 183 | * Post type render |
| 184 | */ |
| 185 | $post_types = Fns::get_post_types(); |
| 186 | |
| 187 | foreach ( $post_types as $post_type => $label ) { |
| 188 | $_taxonomies = get_object_taxonomies( $post_type, 'object' ); |
| 189 | |
| 190 | if ( empty( $_taxonomies ) ) { |
| 191 | continue; |
| 192 | } |
| 193 | |
| 194 | $post_data[ $data['post_type'] . '_taxonomy' ] = isset( $data[ $data['post_type'] . '_taxonomy' ] ) ? $data[ $data['post_type'] . '_taxonomy' ] : ''; |
| 195 | $post_data[ $data['post_type'] . '_tags' ] = isset( $data[ $data['post_type'] . '_tags' ] ) ? $data[ $data['post_type'] . '_tags' ] : ''; |
| 196 | } |
| 197 | |
| 198 | $template_path = $this->tpg_template_path( $post_data ); |
| 199 | $_layout = $data[ $_prefix . '_layout' ]; |
| 200 | $_layout_style = $data[ $_prefix . '_layout_style' ]; |
| 201 | |
| 202 | ?> |
| 203 | |
| 204 | <div class="rt-container-fluid rt-tpg-container tpg-el-main-wrapper clearfix <?php echo esc_attr( $_layout . '-main' ); ?>" |
| 205 | id="<?php echo esc_attr( $layoutID ); ?>" |
| 206 | data-layout="<?php echo esc_attr( $data[ $_prefix . '_layout' ] ); ?>" |
| 207 | data-grid-style="<?php echo esc_attr( $data[ $_prefix . '_layout_style' ] ); ?>" |
| 208 | data-sc-id="elementor" |
| 209 | data-el-settings='<?php Fns::print_html( htmlspecialchars( wp_json_encode( $post_data ) ), true ); ?>' |
| 210 | data-el-query='<?php Fns::print_html( htmlspecialchars( wp_json_encode( $query_args ) ), true ); ?>' |
| 211 | data-el-path='<?php echo esc_attr( $template_path ); ?>' |
| 212 | > |
| 213 | <?php |
| 214 | |
| 215 | $settings = get_option( rtTPG()->options['settings'] ); |
| 216 | if ( isset( $settings['tpg_load_script'] ) && isset( $settings['tpg_enable_preloader'] ) ) { |
| 217 | ?> |
| 218 | <div id="bottom-script-loader" class="bottom-script-loader"> |
| 219 | <div class="rt-ball-clip-rotate"> |
| 220 | <div></div> |
| 221 | </div> |
| 222 | </div> |
| 223 | <?php |
| 224 | } |
| 225 | |
| 226 | $wrapper_class = []; |
| 227 | $wrapper_class[] = str_replace( '-2', null, $_layout ); |
| 228 | $wrapper_class[] = 'grid-behaviour'; |
| 229 | $wrapper_class[] = ( in_array( $_layout, [ 'grid-layout2' ] ) ) ? 'tpg-even' : $_layout_style; |
| 230 | $wrapper_class[] = $_prefix . '_layout_wrapper'; |
| 231 | |
| 232 | if ( 'masonry' === $_layout_style && ! in_array( $_layout, [ $this->prefix . '-layout2', $this->prefix . '-layout5', $this->prefix . '-layout6' ] ) ) { |
| 233 | $wrapper_class[] = 'tpg-masonry'; |
| 234 | } |
| 235 | |
| 236 | // section title settings. |
| 237 | echo "<div class='tpg-header-wrapper '>"; |
| 238 | $this->get_section_title( $data ); |
| 239 | echo '</div>'; |
| 240 | ?> |
| 241 | |
| 242 | <div data-title="Loading ..." class="rt-row rt-content-loader <?php echo esc_attr( implode( ' ', $wrapper_class ) ); ?>"> |
| 243 | <?php |
| 244 | if ( $query->have_posts() ) { |
| 245 | $pCount = 1; |
| 246 | |
| 247 | while ( $query->have_posts() ) { |
| 248 | $query->the_post(); |
| 249 | set_query_var( 'tpg_post_count', $pCount ); |
| 250 | set_query_var( 'tpg_total_posts', $query->post_count ); |
| 251 | $this->tpg_template( $post_data ); |
| 252 | $pCount ++; |
| 253 | // rtTPGElementorHelper::tpg_template($data, $this->tpg_dir); |
| 254 | } |
| 255 | } else { |
| 256 | if ( $data['no_posts_found_text'] ) { |
| 257 | printf( "<div class='no_posts_found_text'>%s</div>", esc_html( $data['no_posts_found_text'] ) ); |
| 258 | } else { |
| 259 | printf( "<div class='no_posts_found_text'>%s</div>", esc_html__( 'No post found', 'the-post-grid' ) ); |
| 260 | } |
| 261 | } |
| 262 | wp_reset_postdata(); |
| 263 | ?> |
| 264 | </div> |
| 265 | |
| 266 | <?php Fns::print_html( $this->get_pagination_markup( $query, $data ) ); ?> |
| 267 | </div> |
| 268 | <?php |
| 269 | if ( 'masonry' === $data[ $_prefix . '_layout_style' ] && \Elementor\Plugin::$instance->editor->is_edit_mode() ) { |
| 270 | ?> |
| 271 | <script>jQuery('.rt-row.rt-content-loader.tpg-masonry').isotope();</script> |
| 272 | <?php |
| 273 | } |
| 274 | do_action( 'tpg_elementor_script' ); |
| 275 | } |
| 276 | |
| 277 | } |
| 278 |