Example #1
0
    function etheme_teaser($atts, $content = null)
    {
        $title = $grid_columns_count = $grid_teasers_count = $grid_layout = $grid_link = $grid_link_target = $pagination = '';
        $grid_template = $grid_thumb_size = $grid_posttypes = $grid_taxomonies = $grid_categories = $posts_in = $posts_not_in = '';
        $grid_content = $el_class = $width = $orderby = $order = $el_position = $isotope_item = $isotope_class = $posted_by = $posted_block = $hover_mask = $border = '';
        extract(shortcode_atts(array('title' => '', 'grid_columns_count' => 4, 'grid_teasers_count' => 8, 'grid_layout' => 'title_thumbnail_text', 'grid_link' => 'link_post', 'grid_link_target' => '_self', 'grid_template' => 'grid', 'grid_thumb_size' => '500x300', 'grid_posttypes' => '', 'border' => 'on', 'pagination' => 'show', 'posted_block' => 'show', 'hover_mask' => 'show', 'grid_taxomonies' => '', 'grid_categories' => '', 'posts_in' => '', 'posts_not_in' => '', 'grid_content' => 'teaser', 'el_class' => '', 'width' => '1/1', 'orderby' => NULL, 'order' => 'DESC', 'el_position' => ''), $atts));
        if ($grid_template == 'grid' || $grid_template == 'filtered_grid') {
            $isotope_item = 'et_isotope-item ';
        } else {
            if ($grid_template == 'carousel') {
                $isotope_item = '';
            }
        }
        $output = '';
        $el_class = WPBakeryShortCode::getExtraClass($el_class);
        $width = '';
        //wpb_translateColumnWidthToSpan( $width );
        $col = 12 / $grid_columns_count;
        $li_span_class = 'col-lg-' . $col;
        $query_args = array();
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        if (is_front_page()) {
            $paged = get_query_var('page') ? get_query_var('page') : 1;
        }
        $query_args['paged'] = $paged;
        $not_in = array();
        if ($posts_not_in != '') {
            $posts_not_in = str_ireplace(" ", "", $posts_not_in);
            $not_in = explode(",", $posts_not_in);
        }
        $link_target = $grid_link_target == '_blank' ? ' target="_blank"' : '';
        //exclude current post/page from query
        if ($posts_in == '') {
            global $post;
            array_push($not_in, $post->ID);
        } else {
            if ($posts_in != '') {
                $posts_in = str_ireplace(" ", "", $posts_in);
                $query_args['post__in'] = explode(",", $posts_in);
            }
        }
        if ($posts_in == '' || $posts_not_in != '') {
            $query_args['post__not_in'] = $not_in;
        }
        // Post teasers count
        if ($grid_teasers_count != '' && !is_numeric($grid_teasers_count)) {
            $grid_teasers_count = -1;
        }
        if ($grid_teasers_count != '' && is_numeric($grid_teasers_count)) {
            $query_args['posts_per_page'] = $grid_teasers_count;
        }
        // Post types
        $pt = array();
        if ($grid_posttypes != '') {
            $grid_posttypes = explode(",", $grid_posttypes);
            foreach ($grid_posttypes as $post_type) {
                array_push($pt, $post_type);
            }
            $query_args['post_type'] = $pt;
        }
        // Taxonomies
        $taxonomies = array();
        if ($grid_taxomonies != '') {
            $grid_taxomonies = explode(",", $grid_taxomonies);
            foreach ($grid_taxomonies as $taxom) {
                array_push($taxonomies, $taxom);
            }
        }
        // Narrow by categories
        if ($grid_categories != '') {
            $grid_categories = explode(",", $grid_categories);
            $gc = array();
            foreach ($grid_categories as $grid_cat) {
                array_push($gc, $grid_cat);
            }
            $gc = implode(",", $gc);
            ////http://snipplr.com/view/17434/wordpress-get-category-slug/
            $query_args['category_name'] = $gc;
            $taxonomies = get_taxonomies('', 'object');
            $query_args['tax_query'] = array('relation' => 'OR');
            foreach ($taxonomies as $t) {
                if (in_array($t->object_type[0], $pt)) {
                    $query_args['tax_query'][] = array('taxonomy' => $t->name, 'terms' => $grid_categories, 'field' => 'slug');
                }
            }
        }
        // Order posts
        if ($orderby != NULL) {
            $query_args['orderby'] = $orderby;
        }
        $query_args['order'] = $order;
        // Run query
        $my_query = new WP_Query($query_args);
        //global $_wp_additional_image_sizes;
        $teasers = '';
        $teaser_categories = array();
        if ($grid_template == 'filtered_grid' && empty($grid_taxomonies)) {
            $taxonomies = get_object_taxonomies(!empty($query_args['post_type']) ? $query_args['post_type'] : get_post_types(array('public' => false, 'name' => 'attachment'), 'names', 'NOT'));
        }
        if ($posted_block == 'show') {
            add_filter('vc_teaser_grid_title', 'etheme_posted_info');
        }
        $posts_Ids = array();
        while ($my_query->have_posts()) {
            $link_title_start = $link_image_start = $p_link = $link_image_end = $p_img_large = '';
            $my_query->the_post();
            $posts_Ids[] = $my_query->post->ID;
            $categories_css = '';
            if ($grid_template == 'filtered_grid') {
                /** @var $post_cate``gories get list of categories */
                // $post_categories = get_the_category($my_query->post->ID);
                $post_categories = wp_get_object_terms($my_query->post->ID, $taxonomies);
                if (!is_wp_error($post_categories)) {
                    foreach ($post_categories as $cat) {
                        if (!in_array($cat->term_id, $teaser_categories)) {
                            $teaser_categories[] = $cat->term_id;
                        }
                        $categories_css .= ' grid-cat-' . $cat->term_id;
                    }
                }
            }
            $post_title = the_title("", "", false);
            $post_id = $my_query->post->ID;
            $teaser_post_type = 'posts_grid_teaser_' . $my_query->post->post_type . ' ';
            if ($grid_content == 'teaser') {
                $content = apply_filters('the_excerpt', get_the_excerpt());
            } else {
                $content = get_the_content();
                $content = apply_filters('the_content', $content);
                $content = str_replace(']]>', ']]>', $content);
            }
            // $content = ( $grid_content == 'teaser' ) ? apply_filters('the_excerpt', get_the_excerpt()) : get_the_content(); //TODO: get_the_content() rewrite more WP native way.
            $content = wpautop($content);
            $link = '';
            $thumbnail = '';
            // Read more link
            if ($grid_link != 'link_no') {
                $link = '<a class="more-link" href="' . get_permalink($post_id) . '"' . $link_target . ' title="' . sprintf(esc_attr__('Permalink to %s', 'js_composer'), the_title_attribute('echo=0')) . '">' . __("Read more", "js_composer") . '</a>';
            }
            // Thumbnail logic
            if (in_array($grid_layout, array('title_thumbnail_text', 'thumbnail_title_text', 'thumbnail_text', 'thumbnail_title', 'thumbnail', 'title_text'))) {
                $post_thumbnail = $p_img_large = '';
                //$attach_id = get_post_thumbnail_id($post_id);
                $post_thumbnail = wpb_getImageBySize(array('post_id' => $post_id, 'thumb_size' => $grid_thumb_size));
                $thumbnail = $post_thumbnail['thumbnail'];
                $p_img_large = $post_thumbnail['p_img_large'];
            }
            // Link logic
            if ($grid_link != 'link_no') {
                $p_video = '';
                if ($grid_link == 'link_image' || $grid_link == 'link_image_post') {
                    $p_video = get_post_meta($post_id, "_p_video", true);
                }
                if ($grid_link == 'link_post') {
                    $link_image_start = '<a class="link_image" href="' . get_permalink($post_id) . '"' . $link_target . ' title="' . sprintf(esc_attr__('Permalink to %s', 'js_composer'), the_title_attribute('echo=0')) . '">';
                    $link_title_start = '<a class="link_title" href="' . get_permalink($post_id) . '"' . $link_target . ' title="' . sprintf(esc_attr__('Permalink to %s', 'js_composer'), the_title_attribute('echo=0')) . '">';
                } else {
                    if ($grid_link == 'link_image') {
                        if ($p_video != "") {
                            $p_link = $p_video;
                        } else {
                            $p_link = $p_img_large[0];
                        }
                        $link_image_start = '<a class="link_image prettyphoto" href="' . $p_link . '"' . $link_target . ' title="' . the_title_attribute('echo=0') . '">';
                        $link_title_start = '<a class="link_title prettyphoto" href="' . $p_link . '"' . $link_target . ' title="' . the_title_attribute('echo=0') . '">';
                    } else {
                        if ($grid_link == 'link_image_post') {
                            if ($p_video != "") {
                                $p_link = $p_video;
                            } else {
                                $p_link = $p_img_large[0];
                            }
                            $link_image_start = '<a class="link_image prettyphoto" href="' . $p_link . '"' . $link_target . ' title="' . the_title_attribute('echo=0') . '">';
                            $link_title_start = '<a class="link_title" href="' . get_permalink($post_id) . '"' . $link_target . ' title="' . sprintf(esc_attr__('Permalink to %s', 'js_composer'), the_title_attribute('echo=0')) . '">';
                        }
                    }
                }
                $link_title_end = $link_image_end = '</a>';
            } else {
                $link_image_start = '';
                $link_title_start = '';
                $link_title_end = $link_image_end = '';
            }
            if ($hover_mask == 'show') {
                $link_image_end .= '
                    <div class="zoom">
                        <div class="btn_group">
                            <a href="' . etheme_get_image(get_post_thumbnail_id($post_id)) . '" rel="lightbox"><span>View large</span></a>
                            <a href="' . get_permalink($post_id) . '"><span>More details</span></a>
                        </div>
                        <i class="bg"></i>
                    </div>
			    ';
            }
            $teasers .= '<div class="' . $isotope_item . apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, $li_span_class, 'vc_teaser_grid_li') . $categories_css . '">';
            // If grid layout is: Title + Thumbnail + Text
            if ($grid_layout == 'title_thumbnail_text') {
                if ($post_title) {
                    $to_filter = '<h4 class="post-title">' . $link_title_start . $post_title . $link_title_end . '</h2>';
                    $teasers .= apply_filters('vc_teaser_grid_title', $to_filter, array("grid_layout" => $grid_layout, "ID" => $post_id, "title" => $post_title, "media_link" => $p_link));
                }
                if ($thumbnail) {
                    $to_filter = '<div class="post-thumb">' . $link_image_start . $thumbnail . $link_image_end . '</div>';
                    $teasers .= apply_filters('vc_teaser_grid_thumbnail', $to_filter, array("grid_layout" => $grid_layout, "ID" => $post_id, "thumbnail" => $thumbnail, "media_link" => $p_link));
                }
                if ($content) {
                    $to_filter = '<div class="entry-content">' . $content . '</div>';
                    $teasers .= apply_filters('vc_teaser_grid_content', $to_filter, array("grid_layout" => $grid_layout, "ID" => $post_id, "content" => $content, "media_link" => $p_link));
                }
            } else {
                if ($grid_layout == 'thumbnail_title_text') {
                    if ($thumbnail) {
                        $to_filter = '<div class="post-thumb">' . $link_image_start . $thumbnail . $link_image_end . '</div>';
                        $teasers .= apply_filters('vc_teaser_grid_thumbnail', $to_filter, array("grid_layout" => $grid_layout, "ID" => $post_id, "thumbnail" => $thumbnail, "media_link" => $p_link));
                    }
                    if ($post_title && $content) {
                        $teasers .= '<div class="teaser-post-info">';
                    }
                    if ($post_title) {
                        $to_filter = '<h4 class="post-title">' . $link_title_start . $post_title . $link_title_end . '</h2>';
                        $teasers .= apply_filters('vc_teaser_grid_title', $to_filter, array("grid_layout" => $grid_layout, "ID" => $post_id, "title" => $post_title, "media_link" => $p_link));
                    }
                    if ($content) {
                        $to_filter = '<div class="entry-content">' . $content . '</div>';
                        $teasers .= apply_filters('vc_teaser_grid_content', $to_filter, array("grid_layout" => $grid_layout, "ID" => $post_id, "content" => $content, "media_link" => $p_link));
                    }
                    if ($post_title && $content) {
                        $teasers .= '</div>';
                    }
                } else {
                    if ($grid_layout == 'thumbnail_text') {
                        if ($thumbnail) {
                            $to_filter = '<div class="post-thumb">' . $link_image_start . $thumbnail . $link_image_end . '</div>';
                            $teasers .= apply_filters('vc_teaser_grid_thumbnail', $to_filter, array("grid_layout" => $grid_layout, "ID" => $post_id, "thumbnail" => $thumbnail, "media_link" => $p_link));
                        }
                        if ($content) {
                            $to_filter = '<div class="teaser-post-info entry-content">' . $content . '</div>';
                            $teasers .= apply_filters('vc_teaser_grid_content', $to_filter, array("grid_layout" => $grid_layout, "ID" => $post_id, "content" => $content, "media_link" => $p_link));
                        }
                    } else {
                        if ($grid_layout == 'thumbnail_title') {
                            if ($thumbnail) {
                                $to_filter = '<div class="post-thumb">' . $link_image_start . $thumbnail . $link_image_end . '</div>';
                                $teasers .= apply_filters('vc_teaser_grid_thumbnail', $to_filter, array("grid_layout" => $grid_layout, "ID" => $post_id, "thumbnail" => $thumbnail, "media_link" => $p_link));
                            }
                            if ($post_title) {
                                $to_filter = '<h4 class="teaser-post-info post-title">' . $link_title_start . $post_title . $link_title_end . '</h2>';
                                $teasers .= apply_filters('vc_teaser_grid_title', $to_filter, array("grid_layout" => $grid_layout, "ID" => $post_id, "title" => $post_title, "media_link" => $p_link));
                            }
                        } else {
                            if ($grid_layout == 'thumbnail') {
                                if ($thumbnail) {
                                    $to_filter = '<div class="post-thumb">' . $link_image_start . $thumbnail . $link_image_end . '</div>';
                                    $teasers .= apply_filters('vc_teaser_grid_thumbnail', $to_filter, array("grid_layout" => $grid_layout, "ID" => $post_id, "thumbnail" => $thumbnail, "media_link" => $p_link));
                                }
                            } else {
                                if ($grid_layout == 'title_text') {
                                    if ($post_title) {
                                        $to_filter = '<h4 class="post-title">' . $link_title_start . $post_title . $link_title_end . '</h2>';
                                        $teasers .= apply_filters('vc_teaser_grid_title', $to_filter, array("grid_layout" => $grid_layout, "ID" => $post_id, "title" => $post_title, "media_link" => $p_link));
                                    }
                                    if ($content) {
                                        $to_filter = '<div class="entry-content">' . $content . '</div>';
                                        $teasers .= apply_filters('vc_teaser_grid_content', $to_filter, array("grid_layout" => $grid_layout, "ID" => $post_id, "content" => $content, "media_link" => $p_link));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            $teasers .= '</div> ' . WPBakeryShortCode::endBlockComment('single teaser');
        }
        // endwhile loop
        wp_reset_query();
        if ($grid_template == 'filtered_grid' && $teasers && !empty($teaser_categories)) {
            /*
            $categories_list = wp_list_categories(array(
                'orderby' => 'name',
                'walker' => new Teaser_Grid_Category_Walker(),
                'include' => implode(',', $teaser_categories),
                'show_option_none'   => __('No categories', 'js_composer'),
                'echo' => false
            ));
            */
            $categories_array = get_terms($taxonomies, array('orderby' => 'name', 'include' => implode(',', $teaser_categories)));
            $categories_list_output = '<ul class="et_categories_filter clearfix">';
            $categories_list_output .= '<li class="active"><a href="#" data-filter="*" class="button active">' . __('All', 'js_composer') . '</a></li>';
            if (!is_wp_error($categories_array)) {
                foreach ($categories_array as $cat) {
                    $categories_list_output .= '<li><a href="#" data-filter=".grid-cat-' . $cat->term_id . '" class="button">' . esc_attr($cat->name) . '</a></li>';
                }
            }
            $categories_list_output .= '</ul><div class="clearfix"></div>';
        } else {
            $categories_list_output = '';
        }
        $box_id = rand(1000, 10000);
        if ($grid_template == 'grid' || $grid_template == 'filtered_grid') {
            $isotope_class = 'et_isotope';
        } else {
            $isotope_class = 'teaser-carousel-' . $box_id;
        }
        if ($teasers) {
            $teasers = '<div class="teaser_grid_container isotope-container">' . $categories_list_output . '<div class="' . $isotope_class . ' et_row clearfix">' . $teasers . '</div></div>';
        } else {
            $teasers = __("Nothing found.", "js_composer");
        }
        $posttypes_teasers = '';
        if (is_array($grid_posttypes)) {
            //$posttypes_teasers_ar = explode(",", $grid_posttypes);
            $posttypes_teasers_ar = $grid_posttypes;
            foreach ($posttypes_teasers_ar as $post_type) {
                $posttypes_teasers .= 'wpb_teaser_grid_' . $post_type . ' ';
            }
        }
        $grid_class = 'wpb_' . $grid_template . ' columns_count_' . $grid_columns_count . ' grid_layout-' . $grid_layout . ' ' . $grid_layout . '_' . ' ' . 'columns_count_' . $grid_columns_count . '_' . $grid_layout . ' ' . $posttypes_teasers . ' teaser-border-' . $border . ' post-by-info-' . $posted_block;
        $css_class = apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'wpb_teaser_grid wpb_content_element ' . $grid_class . $width . $el_class);
        $output .= "\n\t" . '<div class="' . $css_class . '">';
        $output .= "\n\t\t" . '<div class="wpb_wrapper">';
        $output .= $title != '' ? "\n\t\t\t" . '<h3 class="title"><span>' . $title . '</span></h3>' : '';
        //$output .= wpb_widget_title(array('title' => $title, 'extraclass' => 'wpb_teaser_grid_heading'));
        $output .= $teasers;
        $output .= "\n\t\t" . '</div> ' . WPBakeryShortCode::endBlockComment('.wpb_wrapper');
        $output .= "\n\t" . '</div> ' . WPBakeryShortCode::endBlockComment('.wpb_teaser_grid');
        if ($pagination == 'show') {
            $output .= etheme_pagination($my_query, $paged);
        }
        if ($grid_template == 'carousel') {
            $output .= "<script type='text/javascript'>";
            $output .= 'jQuery(".teaser-carousel-' . $box_id . '").owlCarousel({';
            $output .= 'items:4,';
            $output .= 'lazyLoad : true,';
            $output .= 'navigation: true,';
            $output .= 'navigationText:false,';
            $output .= 'rewindNav: false,';
            $output .= 'itemsCustom: [[0, 1], [479,2], [619,2], [768,4],  [1200, 4], [1600, 4]]';
            $output .= '});';
            $output .= '</script>';
        }
        remove_all_filters('vc_teaser_grid_title');
        return $output;
    }
    if (wpsc_product_count() == 0) {
        ?>
  <h3><?php 
        _e('There are no products in this group.', ETHEME_DOMAIN);
        ?>
</h3>
<?php 
    } else {
        ?>
  <div class="toolbar bottom">
    <?php 
        if (wpsc_has_pages_bottom()) {
            ?>
      <div class="pagintaion">
        <?php 
            etheme_pagination();
            ?>
      </div>
    <?php 
        }
        ?>
    <?php 
        if ($view_mode == 'grid_list') {
            ?>
      <p class="view-mode">
        <label><?php 
            _e('View as:', ETHEME_DOMAIN);
            ?>
</label>
        <span
          class="switcher switchToList <?php