Ejemplo n.º 1
0
function vibe_post_grid($atts, $content = null)
{
    global $vibe_options;
    $error = new VibeErrors();
    if (!isset($atts) || !isset($atts['post_type'])) {
        return $error->get_error('unsaved_editor');
    }
    $attributes = v_get_attributes($atts, "vibe_post_grid");
    if (isset($atts['masonry']) && $atts['masonry']) {
        wp_enqueue_script('masonry-js', VIBE_PLUGIN_URL . '/vibe-shortcodes/js/masonry.min.js', array('jquery'), '1.0', true);
        $atts['custom_css'] .= '.grid.masonry li .block { margin-bottom:' . (isset($atts['gutter']) ? $atts['gutter'] : '30') . 'px;}';
    }
    if ($atts['custom_css'] && strlen($atts['custom_css']) > 5) {
        $output = '<style>' . $atts['custom_css'] . '</style>';
    } else {
        $output = '';
    }
    $output .= "<div {$attributes['class']}{$attributes['inline_styles']}>";
    if (!isset($atts['post_ids']) || strlen($atts['post_ids']) < 2) {
        if (isset($atts['term']) && isset($atts['taxonomy']) && $atts['term'] != 'nothing_selected') {
            if (isset($atts['taxonomy']) && $atts['taxonomy'] != '') {
                $check = term_exists($atts['term'], $atts['taxonomy']);
                if ($atts['term'] != 'nothing_selected') {
                    if ($check == 0 || $check == null || !$check) {
                        $error = new VibeErrors();
                        $output .= $error->get_error('term_taxonomy_mismatch');
                        $output .= '</div>';
                        return $output;
                    }
                }
                $check = is_object_in_taxonomy($atts['post_type'], $atts['taxonomy']);
                if ($check == 0 || $check == null || !$check) {
                    $error = new VibeErrors();
                    $output .= $error->get_error('term_postype_mismatch');
                    $output .= '</div>';
                    return $output;
                }
            }
            if ($atts['column_width'] < 311) {
                $cols = 'small';
            }
            if ($atts['column_width'] >= 311 && $atts['column_width'] < 460) {
                $cols = 'medium';
            }
            if ($atts['column_width'] >= 460 && $atts['column_width'] < 769) {
                $cols = 'big';
            }
            if ($atts['column_width'] >= 769) {
                $cols = 'full';
            }
            if (isset($atts['taxonomy']) && $atts['taxonomy'] != '') {
                if ($atts['taxonomy'] == 'category') {
                    $atts['taxonomy'] = 'category_name';
                }
                if ($atts['taxonomy'] == 'tag') {
                    $atts['taxonomy'] = 'tag_name';
                }
            }
            $query_args = array('post_type' => $atts['post_type'], $atts['taxonomy'] => $atts['term'], 'posts_per_page' => $atts['grid_number']);
        } else {
            $query_args = array('post_type' => $atts['post_type'], 'posts_per_page' => $atts['grid_number']);
        }
        if ($atts['post_type'] == 'course') {
            switch ($atts['course_style']) {
                case 'popular':
                    $query_args['orderby'] = 'meta_value_num';
                    $query_args['meta_key'] = 'vibe_students';
                    break;
                case 'rated':
                    $query_args['orderby'] = 'meta_value_num';
                    $query_args['meta_key'] = 'average_rating';
                    break;
                case 'reviews':
                    $query_args['orderby'] = 'comment_count';
                    break;
                case 'start_date':
                    $args['orderby'] = 'meta_value';
                    $args['meta_key'] = 'vibe_start_date';
                    $args['meta_type'] = 'DATE';
                    $args['order'] = 'ASC';
                    break;
                case 'random':
                    $query_args['orderby'] = 'rand';
                    break;
            }
            $query_args = apply_filters('wplms_grid_course_filters', $query_args);
        }
    } else {
        $cus_posts_ids = explode(",", $atts['post_ids']);
        $query_args = array('post_type' => $atts['post_type'], 'post__in' => $cus_posts_ids);
    }
    global $paged;
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    if (get_query_var('paged')) {
        $paged = get_query_var('paged');
    } elseif (get_query_var('page')) {
        $paged = get_query_var('page');
    } else {
        $paged = 1;
    }
    if (isset($atts['pagination']) && $atts['pagination']) {
        $query_args['paged'] = $paged;
    }
    $istyle = '';
    query_posts($query_args);
    $masonry = $style = $rel = '';
    if (isset($atts['masonry']) && $atts['masonry']) {
        $atts['grid_columns'] = ' grid-item';
        $style = 'style="width:' . $atts['column_width'] . 'px;"';
        $masonry = 'masonry';
        $istyle .= ' data-width="' . $atts['column_width'] . '" data-gutter="' . (isset($atts['gutter']) ? $atts['gutter'] : '30') . '"';
        // Rel-width used in Masonry+infinite scroll
    } else {
        $cols = $atts['grid_columns'];
    }
    $infinite = '';
    if (isset($atts['infinite']) && $atts['infinite']) {
        $infinite = ' inifnite_scroll';
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        $rel = 'data-page=' . $paged;
    }
    if (isset($atts['title']) && $atts['title'] && $atts['title'] != 'Content') {
        $ntitle = $atts['title'];
        $ntitle = preg_replace('/[^a-zA-Z0-9\']/', '_', $ntitle);
        $ntitle = str_replace("'", '', $ntitle);
        $output .= '<div id="' . $ntitle . '"></div>';
    }
    global $wp_query;
    if ($atts['show_title']) {
        $output .= '<h3 class="heading"><span>' . $atts['title'] . '</span></h3>';
    }
    $output .= '<div class="vibe_grid ' . $infinite . ' ' . $masonry . '" ' . $rel . '><div class="wp_query_args" data-max-pages="' . $wp_query->max_num_pages . '">' . json_encode($atts) . '</div>';
    if (have_posts()) {
        $output .= '<ul class="grid ' . $masonry . '" ' . $istyle . '>';
        while (have_posts()) {
            the_post();
            global $post;
            $output .= '<li class="' . $atts['grid_columns'] . '" ' . $style . '>';
            $output .= thumbnail_generator($post, $atts['featured_style'], $cols, $atts['grid_excerpt_length'], $atts['grid_link'], $atts['grid_lightbox']);
            $output .= '</li>';
        }
        $output .= '</ul>';
    } else {
        $error = new VibeErrors();
        $output .= $error->get_error('no_posts');
    }
    wp_reset_postdata();
    $output .= '</div>';
    if (isset($atts['infinite']) && $atts['infinite']) {
        $output .= '<div class="load_grid"><span>' . __('Loading..', 'vibe-customtypes') . '</i></span></div>
                        <div class="end_grid"><span>' . __('No more to load', 'vibe-customtypes') . '</i></span></div>';
    }
    $output .= "</div>";
    if (isset($atts['pagination']) && $atts['pagination']) {
        ob_start();
        pagination();
        $output .= ob_get_contents();
        ob_end_clean();
    }
    wp_reset_query();
    wp_reset_postdata();
    return $output;
}
Ejemplo n.º 2
0
    function widget($args, $instance)
    {
        extract($args);
        //Our variables from the widget settings.
        $title = apply_filters('widget_title', $instance['title']);
        echo $before_widget;
        // Display the widget title
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        if (isset($instance['taxonomy']) && $instance['taxonomy'] != '') {
            $check = term_exists($instance['term'], $instance['taxonomy']);
            if ($check == 0 || $check == null || !$check) {
                $error = new VibeErrors();
                echo $error->get_error('term_taxonomy_mismatch');
            }
            $check = is_object_in_taxonomy($instance['type'], $instance['taxonomy']);
            if ($check == 0 || $check == null || !$check) {
                $error = new VibeErrors();
                echo $error->get_error('term_postype_mismatch');
            }
        }
        $query = array('posts_per_page' => $instance['num']);
        // if($instance['type'] != 'post') {
        $query['post_type'] = $instance['type'];
        //}
        if (!empty($instance['taxonomy'])) {
            if ($instance['taxonomy'] == 'category') {
                $instance['taxonomy'] = 'category_name';
            }
            if ($instance['taxonomy'] == 'tag') {
                $instance['taxonomy'] = 'tag_name';
            }
            $query[$instance['taxonomy']] = $instance['term'];
        }
        if ($instance['sort'] == 'popular') {
            $query['orderby'] = 'comment_count';
        }
        $loop = new WP_Query($query);
        ?>
                    <div class="postlist <?php 
        echo $instance['theme'] . ' post' . $instance['size'];
        ?>
">
         <ul class="vibeposts">
                             
                <?php 
        if ($instance['style'] == 'post') {
            while ($loop->have_posts()) {
                $loop->the_post();
                $thumb = get_the_post_thumbnail($loop->post->ID, $instance['size']);
                if (isset($instance['chars']) && $instance['chars'] != '') {
                    $chars = intval($instance['chars']);
                } else {
                    $chars = 80;
                }
                echo '
                              <li>
                                <article>
                                  <div class="post_thumb">';
                echo '<a href="' . get_permalink($loop->post->ID) . '" class="' . $instance['size'] . '_thumb">' . $thumb . '</a>
                                  </div>
                                  <h4 class="post_title"><a href="' . get_permalink($loop->post->ID) . '">' . get_the_title($loop->post->ID) . '</a></h4>
                                  <p class="post_excerpt">' . custom_excerpt($chars) . '</p>
                                  </article>
                              </li>';
            }
        }
        if ($instance['style'] == 'imagetitle') {
            while ($loop->have_posts()) {
                $loop->the_post();
                $thumb = get_the_post_thumbnail($loop->post->ID, $instance['size']);
                echo '<li>
                                  <article>
                                    <div class="post_thumb">';
                echo '<a href="' . get_permalink($loop->post->ID) . '">' . $thumb . '</a>
                                    </div>
                                    <h5><a href="' . get_permalink($loop->post->ID) . '">' . get_the_title($loop->post->ID) . '</a></h5>
                                    </article>
                                </li>';
            }
        }
        if ($instance['style'] == 'image') {
            while ($loop->have_posts()) {
                $loop->the_post();
                $thumb = get_the_post_thumbnail($loop->post->ID, $instance['size']);
                echo '<li>
                                <div class="post_thumb imageonly">';
                echo '<a href="' . get_permalink($loop->post->ID) . '">' . $thumb . '</a>
                                </div>
                            </li>';
            }
        }
        if ($instance['style'] == 'title') {
            while ($loop->have_posts()) {
                $loop->the_post();
                echo '<li>
                                  <h5><a href="' . get_permalink($loop->post->ID) . '">' . get_the_title($loop->post->ID) . '</a></h5>
                              </li>';
            }
        }
        ?>
              </ul> 
          </div>  
<?php 
        // Restore original Query & Post Data
        wp_reset_query();
        wp_reset_postdata();
        echo $after_widget;
    }