コード例 #1
0
    function shortcode_callback($atts, $content = null, $function_name)
    {
        /**
         * Cached $wp_filter so it can be restored at the end of the callback.
         * This is needed because this callback uses the_content filter / calls a function
         * which uses the_content filter. WordPress doesn't support nested filter
         */
        global $wp_filter;
        $wp_filter_cache = $wp_filter;
        $module_id = $this->shortcode_atts['module_id'];
        $module_class = $this->shortcode_atts['module_class'];
        $fullwidth = $this->shortcode_atts['fullwidth'];
        $posts_number = $this->shortcode_atts['posts_number'];
        $include_categories = $this->shortcode_atts['include_categories'];
        $meta_date = $this->shortcode_atts['meta_date'];
        $show_thumbnail = $this->shortcode_atts['show_thumbnail'];
        $show_content = $this->shortcode_atts['show_content'];
        $show_author = $this->shortcode_atts['show_author'];
        $show_date = $this->shortcode_atts['show_date'];
        $show_categories = $this->shortcode_atts['show_categories'];
        $show_comments = $this->shortcode_atts['show_comments'];
        $show_pagination = $this->shortcode_atts['show_pagination'];
        $background_layout = $this->shortcode_atts['background_layout'];
        $show_more = $this->shortcode_atts['show_more'];
        $offset_number = $this->shortcode_atts['offset_number'];
        $masonry_tile_background_color = $this->shortcode_atts['masonry_tile_background_color'];
        $use_dropshadow = $this->shortcode_atts['use_dropshadow'];
        $overlay_icon_color = $this->shortcode_atts['overlay_icon_color'];
        $hover_overlay_color = $this->shortcode_atts['hover_overlay_color'];
        $hover_icon = $this->shortcode_atts['hover_icon'];
        $use_overlay = $this->shortcode_atts['use_overlay'];
        global $paged;
        $module_class = ET_Builder_Element::add_module_order_class($module_class, $function_name);
        $container_is_closed = false;
        // remove all filters from WP audio shortcode to make sure current theme doesn't add any elements into audio module
        remove_all_filters('wp_audio_shortcode_library');
        remove_all_filters('wp_audio_shortcode');
        remove_all_filters('wp_audio_shortcode_class');
        if ('' !== $masonry_tile_background_color) {
            ET_Builder_Element::set_style($function_name, array('selector' => '%%order_class%%.et_pb_blog_grid .et_pb_post', 'declaration' => sprintf('background-color: %1$s;', esc_html($masonry_tile_background_color))));
        }
        if ('' !== $overlay_icon_color) {
            ET_Builder_Element::set_style($function_name, array('selector' => '%%order_class%% .et_overlay:before', 'declaration' => sprintf('color: %1$s !important;', esc_html($overlay_icon_color))));
        }
        if ('' !== $hover_overlay_color) {
            ET_Builder_Element::set_style($function_name, array('selector' => '%%order_class%% .et_overlay', 'declaration' => sprintf('background-color: %1$s;', esc_html($hover_overlay_color))));
        }
        if ('on' === $use_overlay) {
            $data_icon = '' !== $hover_icon ? sprintf(' data-icon="%1$s"', esc_attr(et_pb_process_font_icon($hover_icon))) : '';
            $overlay_output = sprintf('<span class="et_overlay%1$s"%2$s></span>', '' !== $hover_icon ? ' et_pb_inline_icon' : '', $data_icon);
        }
        $overlay_class = 'on' === $use_overlay ? ' et_pb_has_overlay' : '';
        if ('on' !== $fullwidth) {
            if ('on' === $use_dropshadow) {
                $module_class .= ' et_pb_blog_grid_dropshadow';
            }
            wp_enqueue_script('salvattore');
            $background_layout = 'light';
        }
        $args = array('posts_per_page' => (int) $posts_number);
        $et_paged = is_front_page() ? get_query_var('page') : get_query_var('paged');
        if (is_front_page()) {
            $paged = $et_paged;
        }
        if ('' !== $include_categories) {
            $args['cat'] = $include_categories;
        }
        if (!is_search()) {
            $args['paged'] = $et_paged;
        }
        if ('' !== $offset_number && !empty($offset_number)) {
            /**
             * Offset + pagination don't play well. Manual offset calculation required
             * @see: https://codex.wordpress.org/Making_Custom_Queries_using_Offset_and_Pagination
             */
            if ($paged > 1) {
                $args['offset'] = ($et_paged - 1) * intval($posts_number) + intval($offset_number);
            } else {
                $args['offset'] = intval($offset_number);
            }
        }
        if (is_single() && !isset($args['post__not_in'])) {
            $args['post__not_in'] = array(get_the_ID());
        }
        ob_start();
        query_posts($args);
        if (have_posts()) {
            while (have_posts()) {
                the_post();
                $post_format = et_pb_post_format();
                $thumb = '';
                $width = 'on' === $fullwidth ? 1080 : 400;
                $width = (int) apply_filters('et_pb_blog_image_width', $width);
                $height = 'on' === $fullwidth ? 675 : 250;
                $height = (int) apply_filters('et_pb_blog_image_height', $height);
                $classtext = 'on' === $fullwidth ? 'et_pb_post_main_image' : '';
                $titletext = get_the_title();
                $thumbnail = get_thumbnail($width, $height, $classtext, $titletext, $titletext, false, 'Blogimage');
                $thumb = $thumbnail["thumb"];
                $no_thumb_class = '' === $thumb || 'off' === $show_thumbnail ? ' et_pb_no_thumb' : '';
                if (in_array($post_format, array('video', 'gallery'))) {
                    $no_thumb_class = '';
                }
                ?>

			<article id="post-<?php 
                the_ID();
                ?>
" <?php 
                post_class('et_pb_post clearfix' . $no_thumb_class . $overlay_class);
                ?>
>

			<?php 
                et_divi_post_format_content();
                if (!in_array($post_format, array('link', 'audio', 'quote'))) {
                    if ('video' === $post_format && false !== ($first_video = et_get_first_video())) {
                        printf('<div class="et_main_video_container">
								%1$s
							</div>', $first_video);
                    } elseif ('gallery' === $post_format) {
                        et_pb_gallery_images('slider');
                    } elseif ('' !== $thumb && 'on' === $show_thumbnail) {
                        if ('on' !== $fullwidth) {
                            echo '<div class="et_pb_image_container">';
                        }
                        ?>
							<a href="<?php 
                        esc_url(the_permalink());
                        ?>
" class="entry-featured-image-url">
								<?php 
                        print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height);
                        ?>
								<?php 
                        if ('on' === $use_overlay) {
                            echo $overlay_output;
                        }
                        ?>
							</a>
					<?php 
                        if ('on' !== $fullwidth) {
                            echo '</div> <!-- .et_pb_image_container -->';
                        }
                    }
                }
                ?>

			<?php 
                if ('off' === $fullwidth || !in_array($post_format, array('link', 'audio', 'quote'))) {
                    ?>
				<?php 
                    if (!in_array($post_format, array('link', 'audio'))) {
                        ?>
					<h2 class="entry-title"><a href="<?php 
                        esc_url(the_permalink());
                        ?>
"><?php 
                        the_title();
                        ?>
</a></h2>
				<?php 
                    }
                    ?>

				<?php 
                    if ('on' === $show_author || 'on' === $show_date || 'on' === $show_categories || 'on' === $show_comments) {
                        printf('<p class="post-meta">%1$s %2$s %3$s %4$s %5$s %6$s %7$s</p>', 'on' === $show_author ? et_get_safe_localization(sprintf(__('by %s', 'et_builder'), '<span class="author vcard">' . et_pb_get_the_author_posts_link() . '</span>')) : '', 'on' === $show_author && 'on' === $show_date ? ' | ' : '', 'on' === $show_date ? et_get_safe_localization(sprintf(__('%s', 'et_builder'), '<span class="published">' . esc_html(get_the_date($meta_date)) . '</span>')) : '', ('on' === $show_author || 'on' === $show_date) && 'on' === $show_categories ? ' | ' : '', 'on' === $show_categories ? get_the_category_list(', ') : '', ('on' === $show_author || 'on' === $show_date || 'on' === $show_categories) && 'on' === $show_comments ? ' | ' : '', 'on' === $show_comments ? sprintf(esc_html(_nx('1 Comment', '%s Comments', get_comments_number(), 'number of comments', 'et_builder')), number_format_i18n(get_comments_number())) : '');
                    }
                    echo '<div class="post-content">';
                    if ('on' === $show_content) {
                        global $more;
                        // page builder doesn't support more tag, so display the_content() in case of post made with page builder
                        if (et_pb_is_pagebuilder_used(get_the_ID())) {
                            $more = 1;
                            $post_content = et_strip_shortcodes(et_delete_post_first_video(get_the_content()));
                            echo apply_filters('the_content', $post_content);
                        } else {
                            $more = null;
                            echo apply_filters('the_content', et_strip_shortcodes(et_delete_post_first_video(get_the_content(esc_html__('read more...', 'et_builder')))));
                        }
                    } else {
                        if (has_excerpt()) {
                            echo et_strip_shortcodes(get_the_excerpt());
                        } else {
                            echo wpautop(et_delete_post_first_video(truncate_post(270, false, '', true)));
                        }
                    }
                    if ('on' !== $show_content) {
                        $more = 'on' == $show_more ? sprintf(' <a href="%1$s" class="more-link" >%2$s</a>', esc_url(get_permalink()), esc_html__('read more', 'et_builder')) : '';
                        echo $more;
                    }
                    echo '</div>';
                    ?>
			<?php 
                }
                // 'off' === $fullwidth || ! in_array( $post_format, array( 'link', 'audio', 'quote', 'gallery'
                ?>

			</article> <!-- .et_pb_post -->
	<?php 
            }
            // endwhile
            if ('on' === $show_pagination && !is_search()) {
                echo '</div> <!-- .et_pb_posts -->';
                $container_is_closed = true;
                if (function_exists('wp_pagenavi')) {
                    wp_pagenavi();
                } else {
                    if (et_is_builder_plugin_active()) {
                        include ET_BUILDER_PLUGIN_DIR . 'includes/navigation.php';
                    } else {
                        get_template_part('includes/navigation', 'index');
                    }
                }
            }
            wp_reset_query();
        } else {
            if (et_is_builder_plugin_active()) {
                include ET_BUILDER_PLUGIN_DIR . 'includes/no-results.php';
            } else {
                get_template_part('includes/no-results', 'index');
            }
        }
        $posts = ob_get_contents();
        ob_end_clean();
        $class = " et_pb_module et_pb_bg_layout_{$background_layout}";
        $output = sprintf('<div%5$s class="%1$s%3$s%6$s"%7$s>
				%2$s
			%4$s', 'on' === $fullwidth ? 'et_pb_posts' : 'et_pb_blog_grid clearfix', $posts, esc_attr($class), !$container_is_closed ? '</div> <!-- .et_pb_posts -->' : '', '' !== $module_id ? sprintf(' id="%1$s"', esc_attr($module_id)) : '', '' !== $module_class ? sprintf(' %1$s', esc_attr($module_class)) : '', 'on' !== $fullwidth ? ' data-columns' : '');
        if ('on' !== $fullwidth) {
            $output = sprintf('<div class="et_pb_blog_grid_wrapper">%1$s</div>', $output);
        }
        // Restore $wp_filter
        $wp_filter = $wp_filter_cache;
        unset($wp_filter_cache);
        return $output;
    }
コード例 #2
0
            $height = (int) apply_filters('et_pb_index_blog_image_height', 675);
            $classtext = 'et_featured_image';
            $titletext = get_the_title();
            $thumbnail = get_thumbnail($width, $height, $classtext, $titletext, $titletext, false, 'Blogimage');
            $thumb = $thumbnail["thumb"];
            $post_format = et_pb_post_format();
            if ('video' === $post_format && false !== ($first_video = et_get_first_video())) {
                printf('<div class="et_main_video_container">
											%1$s
										</div>', $first_video);
            } else {
                if (!in_array($post_format, array('gallery', 'link', 'quote')) && 'on' === et_get_option('divi_thumbnails', 'on') && '' !== $thumb) {
                    print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height);
                } else {
                    if ('gallery' === $post_format) {
                        et_pb_gallery_images();
                    }
                }
            }
            ?>

							<?php 
            $text_color_class = et_divi_get_post_text_color();
            $inline_style = et_divi_get_post_bg_inline_style();
            switch ($post_format) {
                case 'audio':
                    printf('<div class="et_audio_content%1$s"%2$s>
												%3$s
											</div>', esc_attr($text_color_class), $inline_style, et_pb_get_audio_player());
                    break;
                case 'quote':
コード例 #3
0
ファイル: main-modules.php プロジェクト: skonina/M20_masonry
    function shortcode_callback($atts, $content = null, $function_name)
    {
        $module_id = $this->shortcode_atts['module_id'];
        $module_class = $this->shortcode_atts['module_class'];
        $fullwidth = $this->shortcode_atts['fullwidth'];
        $posts_number = $this->shortcode_atts['posts_number'];
        $include_categories = $this->shortcode_atts['include_categories'];
        $meta_date = $this->shortcode_atts['meta_date'];
        $show_thumbnail = $this->shortcode_atts['show_thumbnail'];
        $show_content = $this->shortcode_atts['show_content'];
        $show_author = $this->shortcode_atts['show_author'];
        $show_date = $this->shortcode_atts['show_date'];
        $show_categories = $this->shortcode_atts['show_categories'];
        $show_comments = $this->shortcode_atts['show_comments'];
        $show_pagination = $this->shortcode_atts['show_pagination'];
        $background_layout = $this->shortcode_atts['background_layout'];
        $show_more = $this->shortcode_atts['show_more'];
        $offset_number = $this->shortcode_atts['offset_number'];
        $masonry_tile_background_color = $this->shortcode_atts['masonry_tile_background_color'];
        $use_dropshadow = $this->shortcode_atts['use_dropshadow'];
        global $paged;
        $module_class = ET_Builder_Element::add_module_order_class($module_class, $function_name);
        $container_is_closed = false;
        // remove all filters from WP audio shortcode to make sure current theme doesn't add any elements into audio module
        remove_all_filters('wp_audio_shortcode_library');
        remove_all_filters('wp_audio_shortcode');
        remove_all_filters('wp_audio_shortcode_class');
        if ('' !== $masonry_tile_background_color) {
            ET_Builder_Element::set_style($function_name, array('selector' => '%%order_class%%.et_pb_blog_grid .et_pb_post', 'declaration' => sprintf('background-color: %1$s;', esc_html($masonry_tile_background_color))));
        }
        if ('on' !== $fullwidth) {
            if ('on' === $use_dropshadow) {
                $module_class .= ' et_pb_blog_grid_dropshadow';
            }
            wp_enqueue_script('salvattore');
            $background_layout = 'light';
        }
        $args = array('posts_per_page' => (int) $posts_number);
        $et_paged = is_front_page() ? get_query_var('page') : get_query_var('paged');
        if (is_front_page()) {
            $paged = $et_paged;
        }
        if ('' !== $include_categories) {
            $args['cat'] = $include_categories;
        }
        if (!is_search()) {
            $args['paged'] = $et_paged;
        }
        if ('' !== $offset_number && !empty($offset_number)) {
            /**
             * Offset + pagination don't play well. Manual offset calculation required
             * @see: https://codex.wordpress.org/Making_Custom_Queries_using_Offset_and_Pagination
             */
            if ($paged > 1) {
                $args['offset'] = ($et_paged - 1) * intval($posts_number) + intval($offset_number);
            } else {
                $args['offset'] = intval($offset_number);
            }
        }
        if (is_single() && !isset($args['post__not_in'])) {
            $args['post__not_in'] = array(get_the_ID());
        }
        ob_start();
        query_posts($args);
        if (have_posts()) {
            ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/masonry/3.3.2/masonry.pkgd.js"></script>
			<div class="grid js-masonry"
  data-masonry-options='{ "itemSelector": ".new-post", "columnWidth": ".grid-sizer", "percentPosition": true}'>
  <div class="grid-sizer"></div>
  <?php 
            while (have_posts()) {
                the_post();
                $post_format = et_pb_post_format();
                $thumb = '';
                $width = 'on' === $fullwidth ? 1080 : 400;
                $width = (int) apply_filters('et_pb_blog_image_width', $width);
                $height = 'on' === $fullwidth ? 675 : 250;
                $height = (int) apply_filters('et_pb_blog_image_height', $height);
                $classtext = 'on' === $fullwidth ? 'et_pb_post_main_image' : '';
                $titletext = get_the_title();
                $thumbnail = get_thumbnail($width, $height, $classtext, $titletext, $titletext, false, 'Blogimage');
                $thumb = $thumbnail["thumb"];
                $no_thumb_class = '' === $thumb || 'off' === $show_thumbnail ? ' et_pb_no_thumb' : '';
                if (in_array($post_format, array('video', 'gallery'))) {
                    $no_thumb_class = '';
                }
                ?>

			<article onclick="location.href='<?php 
                the_permalink();
                ?>
';" style="cursor:pointer;" id="post-<?php 
                the_ID();
                ?>
"  class="new-post  <?php 
                $cat_color = get_the_category();
                echo $cat_color[1]->slug;
                echo ' ';
                ?>
"<?php 
                post_class('et_pb_post' . $no_thumb_class);
                ?>
>
			<?php 
                et_divi_post_format_content();
                if (!in_array($post_format, array('link', 'audio', 'quote'))) {
                    if ('video' === $post_format && false !== ($first_video = et_get_first_video())) {
                        printf('<div class="et_main_video_container">
								%1$s
							</div>', $first_video);
                    } elseif ('gallery' === $post_format) {
                        et_pb_gallery_images('slider');
                    } elseif ('' !== $thumb && 'on' === $show_thumbnail) {
                        if ('on' !== $fullwidth) {
                            echo '<div class="et_pb_image_container">';
                        }
                        ?>
							<a href="<?php 
                        the_permalink();
                        ?>
">
								<?php 
                        print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height);
                        ?>
							</a>
					<?php 
                        if ('on' !== $fullwidth) {
                            echo '</div> <!-- .et_pb_image_container -->';
                        }
                    }
                }
                ?>

			<?php 
                if ('off' === $fullwidth || !in_array($post_format, array('link', 'audio', 'quote'))) {
                    ?>
				<?php 
                    if (!in_array($post_format, array('link', 'audio'))) {
                        ?>
					<h2 class="entry-title"><a href="<?php 
                        the_permalink();
                        ?>
"><?php 
                        the_title();
                        ?>
</a></h2>
				<?php 
                    }
                    ?>

				<?php 
                    if ('on' === $show_author || 'on' === $show_date || 'on' === $show_categories || 'on' === $show_comments) {
                        printf('<p class="post-meta"> %2$s %3$s %4$s %5$s %6$s </p>', 'on' === $show_author ? sprintf(__('by %s', 'et_builder'), '<span class="author vcard">' . et_pb_get_the_author_posts_link() . '</span>') : '', 'on' === $show_author && 'on' === $show_date ? '  ' : '  ', 'on' === $show_date ? sprintf(__('%s', 'et_builder'), '<span class="published">' . get_the_date('j F') . '</span>') : '  ', ('on' === $show_author || 'on' === $show_date) && 'on' === $show_categories ? '  ~  ' : '', 'on' === $show_categories ? get_the_category_list(' | ') : '   ', ('on' === $show_author || 'on' === $show_date || 'on' === $show_categories) && 'on' === $show_comments ? '  ' : '  ', 'on' === $show_comments ? sprintf(_nx('1 Comment', '%s Comments', get_comments_number(), 'number of comments', 'et_builder'), number_format_i18n(get_comments_number())) : '  ');
                    }
                    $post_content = get_the_content();
                    // do not display the content if it contains Blog or Portfolio modules to avoid infinite loops
                    if (!has_shortcode($post_content, 'et_pb_blog') && !has_shortcode($post_content, 'et_pb_portfolio')) {
                        if ('on' === $show_content) {
                            global $more;
                            // page builder doesn't support more tag, so display the_content() in case of post made with page builder
                            if (et_pb_is_pagebuilder_used(get_the_ID())) {
                                $more = 1;
                                the_content();
                            } else {
                                $more = null;
                                the_content(__('read more...', 'et_builder'));
                            }
                        } else {
                            if (has_excerpt()) {
                                the_excerpt();
                            } else {
                                truncate_post(70);
                            }
                        }
                    } else {
                        if (has_excerpt()) {
                            the_excerpt();
                        }
                    }
                    // if ( 'on' !== $show_content ) {
                    // 	$more = 'on' == $show_more ? sprintf( ' <a href="%1$s" class="more-link" >%2$s</a>' , esc_url( get_permalink() ), __( 'read more', 'et_builder' ) )  : '';
                    // 	echo $more;
                    // }
                    ?>
			<?php 
                }
                // 'off' === $fullwidth || ! in_array( $post_format, array( 'link', 'audio', 'quote', 'gallery'
                ?>

			</article> <!-- .et_pb_post -->
			
	<?php 
            }
            // endwhile
            ?>
</div>

			  <script>
			  if (screen.width < 1200) {
			  	var thingToRemove = document.querySelectorAll(".et_pb_section_0")[0];
				thingToRemove.parentNode.removeChild(thingToRemove);
				var thingToRemove = document.querySelectorAll(".et_pb_section_2")[0];
				thingToRemove.parentNode.removeChild(thingToRemove);
				}
			  </script>

			<?php 
            if ('on' === $show_pagination && !is_search()) {
                echo '</div> <!-- .et_pb_posts -->';
                $container_is_closed = true;
                if (function_exists('wp_pagenavi')) {
                    wp_pagenavi();
                } else {
                    if (et_is_builder_plugin_active()) {
                        include ET_BUILDER_PLUGIN_DIR . 'includes/navigation.php';
                    } else {
                        get_template_part('includes/navigation', 'index');
                    }
                }
            }
            wp_reset_query();
        } else {
            if (et_is_builder_plugin_active()) {
                include ET_BUILDER_PLUGIN_DIR . 'includes/no-results.php';
            } else {
                get_template_part('includes/no-results', 'index');
            }
        }
        $posts = ob_get_contents();
        ob_end_clean();
        $class = " et_pb_module et_pb_bg_layout_{$background_layout}";
        $output = sprintf('<div%5$s class="%1$s%3$s%6$s"%7$s>
				%2$s
			%4$s', 'on' === $fullwidth ? 'et_pb_posts' : 'et_pb_blog_grid clearfix', $posts, esc_attr($class), !$container_is_closed ? '</div> <!-- .et_pb_posts -->' : '', '' !== $module_id ? sprintf(' id="%1$s"', esc_attr($module_id)) : '', '' !== $module_class ? sprintf(' %1$s', esc_attr($module_class)) : '', 'on' !== $fullwidth ? ' data-columns' : '');
        if ('on' !== $fullwidth) {
            $output = sprintf('<div class="et_pb_blog_grid_wrapper">%1$s</div>', $output);
        }
        return $output;
    }