function vce_get_module_query($args = array(), $apply_paged = false) { if ($args['type'] == 'blank') { return false; } global $vce_fa_home_posts, $vce_modules_exclude; $defaults = array('order' => 'date', 'limit' => 4, 'cat' => array(), 'cat_child' => 0, 'manual' => array(), 'tag' => '', 'exclude' => 0, 'time' => 0, 'timeto' => 0); $args = wp_parse_args((array) $args, $defaults); if ($args['curr_page'] > 1 && !$apply_paged && empty($args['exclude'])) { return false; //do not need to run query if "do not duplicate" option is not set } $q_args['post_type'] = 'post'; $q_args['ignore_sticky_posts'] = 1; global $paged; if ($apply_paged) { $q_args['paged'] = $apply_paged; $paged = $apply_paged; } else { $q_args['paged'] = 1; $paged = 1; } if (isset($vce_fa_home_posts) && !empty($vce_fa_home_posts)) { $q_args['post__not_in'] = $vce_fa_home_posts; } if (isset($vce_modules_exclude) && !empty($vce_modules_exclude)) { if (!isset($q_args['post__not_in'])) { $q_args['post__not_in'] = array(); } foreach ($vce_modules_exclude as $ex) { if (!in_array($ex, $q_args['post__not_in'])) { $q_args['post__not_in'][] = $ex; } } } if (!empty($args['manual'])) { $q_args['posts_per_page'] = absint(count($args['manual'])); $q_args['orderby'] = 'post__in'; $q_args['post__in'] = $args['manual']; $q_args['post_type'] = array_keys(get_post_types(array('public' => true))); //support all existing public post types } else { $q_args['posts_per_page'] = absint($args['limit']); if (!empty($args['cat'])) { if ($args['cat_child']) { $child_cat_temp = array(); foreach ($args['cat'] as $parent) { $child_cats = get_categories(array('child_of' => $parent)); if (!empty($child_cats)) { foreach ($child_cats as $child) { $child_cat_temp[] = $child->term_id; } } } $args['cat'] = array_merge($args['cat'], $child_cat_temp); } $q_args['category__in'] = $args['cat']; } $q_args['orderby'] = $args['order']; if ($q_args['orderby'] == 'views' && function_exists('ev_get_meta_key')) { $q_args['orderby'] = 'meta_value_num'; $q_args['meta_key'] = ev_get_meta_key(); } if ($q_args['orderby'] == 'comments_number') { $q_args['orderby'] = 'comment_count'; } if ($q_args['orderby'] == 'title') { $q_args['order'] = 'ASC'; } if ($time_diff = $args['time']) { $q_args['date_query'] = array('after' => date('Y-m-d', vce_calculate_time_diff($time_diff))); } if (($time_diff = $args['timeto']) && !$args['time']) { $q_args['date_query'] = array('before' => date('Y-m-d', vce_calculate_time_diff($time_diff))); } if (!empty($args['tag'])) { $q_args['tag_slug__in'] = explode(',', $args['tag']); } } //print_r( $q_args ); $query = new WP_Query($q_args); if ($args['exclude'] && !is_wp_error($query) && !empty($query)) { foreach ($query->posts as $p) { $vce_modules_exclude[] = $p->ID; } } return $query; }
function widget($args, $instance) { extract($args); $instance = wp_parse_args((array) $instance, $this->defaults); echo $before_widget; $title = apply_filters('widget_title', $instance['title']); if (!empty($title)) { echo $before_title . $title . $after_title; } $q_args = array('post_type' => 'post', 'posts_per_page' => $instance['numposts'], 'ignore_sticky_posts' => 1, 'orderby' => $instance['orderby']); if (!empty($instance['manual']) && !empty($instance['manual'][0])) { $q_args['posts_per_page'] = absint(count($instance['manual'])); $q_args['orderby'] = 'post__in'; $q_args['post__in'] = $instance['manual']; $q_args['post_type'] = array_keys(get_post_types(array('public' => true))); //support all existing public post types } else { if (!empty($instance['auto_detect']) && is_single()) { $cats = get_the_category(); if (!empty($cats)) { foreach ($cats as $k => $cat) { $q_args['category__in'][] = $cat->term_id; } } } else { if (!empty($instance['category'])) { $q_args['category__in'] = is_array($instance['category']) ? $instance['category'] : array($instance['category']); } } if (!empty($instance['tag'])) { $q_args['tag_slug__in'] = explode(',', $instance['tag']); } if ($instance['orderby'] == 'views' && function_exists('ev_get_meta_key')) { $q_args['orderby'] = 'meta_value_num'; $q_args['meta_key'] = ev_get_meta_key(); } if ($instance['orderby'] == 'title') { $q_args['order'] = 'ASC'; } if (!empty($instance['date_limit'])) { $q_args['date_query'] = array('after' => date('Y-m-d', vce_calculate_time_diff($instance['date_limit']))); } } $vce_posts = new WP_Query($q_args); $title_limit = isset($instance['title_limit']) && !empty($instance['title_limit']) ? $instance['title_limit'] : false; $title_more = isset($instance['title_more']) ? $instance['title_more'] : '...'; $img_size = $instance['style'] == 'vce-post-list' ? 'vce-lay-d' : 'vce-fa-grid'; if ($vce_posts->have_posts()) { ?> <?php if ($instance['style'] == 'vce-post-slider' && $vce_posts->post_count == 1) { $instance['style'] = 'vce-post-big'; } ?> <ul class="<?php echo $instance['style']; ?> "> <?php while ($vce_posts->have_posts()) { $vce_posts->the_post(); ?> <li> <?php $p_title = $title_limit ? vce_trim_chars(strip_tags(get_the_title()), $title_limit, $title_more) : get_the_title(); ?> <a href="<?php echo esc_url(get_permalink()); ?> " class="featured_image_sidebar" title="<?php echo esc_attr(get_the_title()); ?> "><span class="vce-post-img"><?php echo vce_featured_image($img_size); ?> </span></a> <div class="vce-posts-wrap"> <?php if (!empty($instance['cat_link'])) { ?> <span class="meta-category"><?php echo vce_get_category(); ?> </span> <?php } ?> <a href="<?php echo esc_url(get_permalink()); ?> " title="<?php echo esc_attr(get_the_title()); ?> " class="vce-post-link"><?php echo $p_title; ?> </a> <?php if (!empty($instance['meta']) && ($meta = vce_get_meta_data('', $instance['meta']))) { ?> <div class="entry-meta"><?php echo $meta; ?> </div> <?php } ?> </div> </li> <?php } ?> </ul> <?php } ?> <?php wp_reset_postdata(); ?> <?php echo $after_widget; }
function vce_get_fa_cat_args() { $args = array('use_fa' => false); //Check category featured area options $obj = get_queried_object(); $meta = vce_get_category_meta($obj->term_id); if ($meta['fa_layout'] == 'inherit') { $fa_layout = vce_get_option('category_fa') ? vce_get_option('category_fa_layout') : false; $num_posts = vce_get_option('category_fa') ? vce_get_option('category_fa_limit') : false; } else { $fa_layout = $meta['fa_layout']; $num_posts = $meta['fa_limit']; } if ($fa_layout) { $q_args['post_type'] = 'post'; $q_args['posts_per_page'] = $num_posts; $q_args['orderby'] = vce_get_option('category_fa_order'); if ($q_args['orderby'] == 'views' && function_exists('ev_get_meta_key')) { $q_args['orderby'] = 'meta_value_num'; $q_args['meta_key'] = ev_get_meta_key(); } if ($q_args['orderby'] == 'comments_number') { $q_args['orderby'] = 'comment_count'; } if ($q_args['orderby'] == 'title') { $q_args['order'] = 'ASC'; } if ($time_diff = vce_get_option('category_fa_time')) { $q_args['date_query'] = array('after' => date('Y-m-d', vce_calculate_time_diff($time_diff))); } $q_args['cat'] = $obj->term_id; $args['fa_posts'] = new WP_Query($q_args); if (!is_wp_error($args['fa_posts']) && !empty($args['fa_posts'])) { $num_posts = count($args['fa_posts']->posts); $fa_layout = explode("_", $fa_layout); $args['both'] = count($fa_layout) == 2 ? true : false; $args['full'] = $fa_layout[0] == 'full' ? true : false; $args['full_slider'] = $num_posts > 1 && !isset($fa_layout[1]) && $fa_layout[0] == 'full' ? true : false; $args['grid'] = in_array('grid', $fa_layout) ? true : false; $args['use_fa'] = true; } if (vce_get_option('category_fa_hide_on_pages') && absint(get_query_var('paged') > 1)) { $args['use_fa'] = false; //Show only on first page } } //print_r($q_args); return $args; }