PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.2.10
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.2.10
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
← All changes | public/class-smart-post-show-public.php +123 -34 2.4.13 → 2.2.10 View file →
@@ -10,8 +10,12 @@
10 10 */
11 11
12 12 /**
13 13 * The public-facing functionality of the plugin.
14 + *
15 + * @package Smart_Post_Show
16 + * @subpackage Smart_Post_Show/public
17 + * @author ShapedPlugin <[email protected]>
14 18 */
15 19 class Smart_Post_Show_Public {
16 20
17 21 /**
@@ -82,10 +86,8 @@
82 86 $post_ids = wp_list_pluck( $pcp_posts->posts, 'ID' );
83 87 $custom_css = '';
84 88 $pcp_custom_css = $pcp_settings['pcp_custom_css'];
85 89 foreach ( $post_ids as $pcp_id ) {
86 - $view_options = get_post_meta( $pcp_id, 'sp_pcp_view_options', true );
87 - $layouts = get_post_meta( $pcp_id, 'sp_pcp_layouts', true );
88 90 // Include dynamic style file.
89 91 include 'dynamic-css/dynamic-css.php';
90 92 }
91 93 if ( ! empty( $pcp_custom_css ) ) {
@@ -105,42 +107,109 @@
105 107 wp_register_script( 'pcp_script', SP_PC_URL . 'public/assets/js/scripts' . $this->suffix . '.js', array( 'jquery' ), SP_PC_VERSION, true );
106 108 }
107 109
108 110 /**
109 - * Full html show.
111 + * PCP shortcode markup wrapper classes.
110 112 *
111 - * @param array $view_options all options.
112 - * @param array $layout show layout.
113 - * @param array $pcp_gl_id Shortcode ID.
114 - * @param array $section_title Shortcode section title.
115 - * @return mixed
113 + * @param string $layout_preset The selected layout name.
114 + * @param int $shortcode_id The shortcode ID.
116 115 */
117 - public static function pc_html_show( $view_options, $layout, $pcp_gl_id, $section_title ) {
118 - $pcp_settings = get_option( 'sp_post_carousel_settings' );
119 - $post_content_sorter = isset( $view_options['post_content_sorter'] ) ? $view_options['post_content_sorter'] : '';
120 - $pcp_content_position = isset( $view_options['post_content_orientation'] ) ? $view_options['post_content_orientation'] : '';
121 - $margin_between_post = isset( $view_options['margin_between_post']['all'] ) ? $view_options['margin_between_post']['all'] : '';
122 - $show_preloader = isset( $view_options['show_preloader'] ) ? $view_options['show_preloader'] : 0;
123 - $query_args = SP_PC_QueryInside::get_filtered_content( $view_options, $pcp_gl_id, $layout );
124 - $pcp_query = new WP_Query( $query_args );
125 - $total_post_count = $pcp_query->post_count;
126 - // Pagination.
127 - $show_pagination = isset( $view_options['show_post_pagination'] ) ? $view_options['show_post_pagination'] : '';
128 - $layout_preset = isset( $layout['pcp_layout_preset'] ) ? $layout['pcp_layout_preset'] : '';
129 - wp_enqueue_script( 'pcp_script' );
130 - $pcp_custom_js = $pcp_settings['pcp_custom_js'];
131 - if ( ! empty( $pcp_custom_js ) ) {
132 - wp_add_inline_script( 'pcp_script', $pcp_custom_js );
116 + public static function pcp_wrapper_classes( $layout_preset, $shortcode_id ) {
117 + $wrapper_class = "sp-pcp-section sp-pcp-container pcp-wrapper-{$shortcode_id}";
118 + switch ( $layout_preset ) {
119 + case 'carousel_layout':
120 + $wrapper_class .= ' pcp-carousel-wrapper';
121 + break;
133 122 }
123 + echo esc_attr( $wrapper_class );
124 + }
134 125
135 - if ( 'carousel_layout' === $layout_preset ) {
136 - require SP_PC_TEMPLATE_PATH . '/carousel.php';
137 - } elseif ( 'grid_layout' === $layout_preset ) {
138 - require SP_PC_TEMPLATE_PATH . '/grid.php';
126 + /**
127 + * Shortcode Wrapper data attributes.
128 + *
129 + * @param int $shortcode_id The shortcode ID.
130 + * @return void
131 + */
132 + public static function wrapper_data( $shortcode_id ) {
133 + $wrapper_data = " data-pagination= 'no_ajax'";
134 +
135 + if ( $shortcode_id ) {
136 + $wrapper_data .= " data-sid={$shortcode_id}";
139 137 }
138 + echo esc_html( $wrapper_data );
139 + }
140 140
141 + /**
142 + * HTML classes for Post.
143 + *
144 + * @return string
145 + */
146 + public static function pcp_alt_post_class() {
147 + $pcp_alt_post_class = 'sp-pcp-post';
148 + return apply_filters( 'post_post_class_name', $pcp_alt_post_class );
141 149 }
150 +
142 151 /**
152 + * Post responsive columns class.
153 + *
154 + * @param string $layout Layout preset.
155 + * @param string $columns Columns number.
156 + * @return string
157 + */
158 + public static function pcp_post_responsive_columns( $layout, $columns ) {
159 + $pcp_post_columns = '';
160 + if ( 'carousel_layout' === $layout ) {
161 + $pcp_post_columns .= ' swiper-slide swiper-lazy';
162 + } else {
163 + $pcp_post_columns .= " sp-pcp-col-xs-$columns[mobile] sp-pcp-col-sm-$columns[mobile_landscape] sp-pcp-col-md-$columns[tablet] sp-pcp-col-lg-$columns[desktop] sp-pcp-col-xl-$columns[lg_desktop]";
164 + }
165 + return $pcp_post_columns;
166 + }
167 +
168 + /**
169 + * Post Loop.
170 + *
171 + * @param array $options Views options.
172 + * @param string $layout Layout preset.
173 + * @param array $sorter Post sorting options.
174 + * @param int $scode_id Shortcode ID.
175 + * @return void
176 + */
177 + public static function pcp_post_loop( $options, $layout, $sorter, $scode_id ) {
178 + global $post;
179 + $number_of_columns = SP_PC_Functions::pcp_metabox_value( 'pcp_number_of_columns', $options );
180 + ?>
181 + <div class="<?php echo esc_attr( self::pcp_post_responsive_columns( $layout, $number_of_columns ) ); ?>">
182 + <div class="sp-pcp-post pcp-item-<?php echo esc_attr( $post->ID ); ?>" data-id="<?php echo esc_attr( $post->ID ); ?>">
183 + <?php
184 + SP_PC_HTML::pcp_post_content_with_thumb( $sorter, $layout, $scode_id, $post, $options );
185 + ?>
186 + </div>
187 + </div>
188 + <?php
189 + }
190 +
191 + /**
192 + * Get all query posts.
193 + *
194 + * @param array $options Views options.
195 + * @param array $layout Layout preset.
196 + * @param array $sorter Post sorting options.
197 + * @param object $pcp_query post query.
198 + * @param int $view_id Shortcode ID.
199 + * @return void
200 + */
201 + public static function pcp_get_posts( $options, $layout, $sorter, $pcp_query, $view_id ) {
202 + $pcp_count = 1;
203 + while ( $pcp_query->have_posts() ) {
204 + $pcp_query->the_post();
205 + self::pcp_post_loop( $options, $layout, $sorter, $view_id );
206 + $pcp_count++;
207 + }
208 + wp_reset_postdata();
209 + }
210 +
211 + /**
143 212 * Function get layout from atts and create class depending on it.
144 213 *
145 214 * @since 2.0
146 215 * @param array $attribute attribute of this shortcode.
@@ -149,16 +218,36 @@
149 218 if ( empty( $attribute['id'] ) ) {
150 219 return;
151 220 }
152 221 $pcp_gl_id = $attribute['id']; // Smart Post Show global ID for Shortcode metaboxes.
153 -
222 + // Setting options.
223 + $pcp_settings = get_option( 'sp_post_carousel_settings' );
154 224 // Preset Layouts.
155 - $layout = get_post_meta( $pcp_gl_id, 'sp_pcp_layouts', true );
225 + $layout = get_post_meta( $pcp_gl_id, 'sp_pcp_layouts', true );
226 + $layout_preset = isset( $layout['pcp_layout_preset'] ) ? $layout['pcp_layout_preset'] : '';
227 + // All the visible options for the Shortcode like – Global, Filter, Display, Popup, Typography etc.
228 + $options = SP_PC_Functions::view_options( $pcp_gl_id );
229 + $view_options = get_post_meta( $pcp_gl_id, 'sp_pcp_view_options', true );
230 + $post_content_sorter = isset( $view_options['post_content_sorter'] ) ? $view_options['post_content_sorter'] : '';
231 + $pcp_content_position = isset( $view_options['post_content_orientation'] ) ? $view_options['post_content_orientation'] : '';
232 + $margin_between_post = isset( $view_options['margin_between_post']['all'] ) ? $view_options['margin_between_post']['all'] : '';
233 + $show_preloader = isset( $view_options['show_preloader'] ) ? $view_options['show_preloader'] : 0;
234 + $query_args = SP_PC_QueryInside::get_filtered_content( $pcp_gl_id );
235 + $pcp_query = new WP_Query( $query_args );
236 + $total_post_count = $pcp_query->post_count;
237 + // Pagination.
238 + $show_pagination = isset( $view_options['show_post_pagination'] ) ? $view_options['show_post_pagination'] : '';
156 239
157 - // All the visible options for the Shortcode like – Global, Filter, Display, Popup, Typography etc.
158 - $view_options = get_post_meta( $pcp_gl_id, 'sp_pcp_view_options', true );
159 - $section_title = get_the_title( $pcp_gl_id );
240 + wp_enqueue_script( 'pcp_script' );
241 + $pcp_custom_js = $pcp_settings['pcp_custom_js'];
242 + if ( ! empty( $pcp_custom_js ) ) {
243 + wp_add_inline_script( 'pcp_script', $pcp_custom_js );
244 + }
160 245 ob_start();
161 - SP_PC_Output::pc_html_show( $view_options, $layout, $pcp_gl_id, $section_title );
246 + if ( 'carousel_layout' === $layout_preset ) {
247 + require SP_PC_TEMPLATE_PATH . '/carousel.php';
248 + } elseif ( 'grid_layout' === $layout_preset ) {
249 + require SP_PC_TEMPLATE_PATH . '/grid.php';
250 + }
162 251 return ob_get_clean();
163 252 }
164 253 }