function vce_pre_get_posts($query) { if (!is_admin() && $query->is_main_query()) { /* Check whether to change number of posts per page for specific archive template if specifed in theme options */ $template = vce_detect_template(); $ppp = vce_get_option($template . '_ppp'); if ($ppp == 'custom') { $ppp = absint(vce_get_option($template . '_ppp_num')); if ($template == 'category') { $obj = get_queried_object(); $cat_meta = vce_get_category_meta($obj->term_id); if ($cat_meta['layout'] != 'inherit' && !empty($cat_meta['ppp'])) { $ppp = $cat_meta['ppp']; } } $query->set('posts_per_page', $ppp); } /*Check for featured area on category page and exclude those posts from main post listing */ if ($template == 'category') { global $vce_cat_fa_args; $vce_cat_fa_args = vce_get_fa_cat_args(); if (vce_get_option('category_fa_not_duplicate')) { if (isset($vce_cat_fa_args['fa_posts']) && !empty($vce_cat_fa_args['fa_posts'])) { $exclude_ids = array(); foreach ($vce_cat_fa_args['fa_posts']->posts as $p) { $exclude_ids[] = $p->ID; } $query->set('post__not_in', $exclude_ids); } } } } }
function vce_category_edit_meta_fields($term) { $vce_meta = vce_get_category_meta($term->term_id); $sidebars_lay = vce_get_sidebar_layouts(true); $sidebars = vce_get_sidebars_list(true); $post_layouts = vce_get_main_layouts(true); $starter_layouts = vce_get_main_layouts(true, true); $fa_layouts = vce_get_featured_area_layouts(true, true); ?> <tr class="form-field"> <th scope="row" valign="top"> <label><?php _e('Featured area layout', THEME_SLUG); ?> </label> </th> <td> <ul class="vce-img-select-wrap next-hide"> <?php foreach ($fa_layouts as $id => $layout) { ?> <li> <?php $selected_class = vce_compare($vce_meta['fa_layout'], $id) ? ' selected' : ''; ?> <img src="<?php echo $layout['img']; ?> " title="<?php echo $layout['title']; ?> " class="vce-img-select<?php echo $selected_class; ?> "> <input type="radio" class="vce-hidden" name="vce[fa_layout]" value="<?php echo $id; ?> " <?php checked($id, $vce_meta['fa_layout']); ?> /> </label> </li> <?php } ?> </ul> <p class="description"><?php _e('Choose featured area layout', THEME_SLUG); ?> </p> </td> </tr> <?php $style = $vce_meta['fa_layout'] == 'inherit' || !$vce_meta['fa_layout'] ? 'style="display:none"' : ''; ?> <tr class="form-field" <?php echo $style; ?> > <th scope="row" valign="top"> <label><?php _e('Featured area posts limit', THEME_SLUG); ?> </label> </th> <td> <input type="text" name="vce[fa_limit]" value="<?php echo $vce_meta['fa_limit']; ?> " style="width: 30px;"/> <?php _e('post(s)', THEME_SLUG); ?> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label><?php _e('Posts main layout', THEME_SLUG); ?> </label> </th> <td> <ul class="vce-img-select-wrap next-hide"> <?php foreach ($post_layouts as $id => $layout) { ?> <li> <?php $selected_class = vce_compare($vce_meta['layout'], $id) ? ' selected' : ''; ?> <img src="<?php echo $layout['img']; ?> " title="<?php echo $layout['title']; ?> " class="vce-img-select<?php echo $selected_class; ?> "> <input type="radio" class="vce-hidden" name="vce[layout]" value="<?php echo $id; ?> " <?php checked($id, $vce_meta['layout']); ?> /> </label> </li> <?php } ?> </ul> <p class="description"><?php _e('Choose posts layout for this category', THEME_SLUG); ?> </p> </td> </tr> <?php $style = $vce_meta['layout'] == 'inherit' ? 'style="display:none"' : ''; ?> <tr class="form-field" <?php echo $style; ?> > <th scope="row" valign="top"> <label><?php _e('Number of posts per page', THEME_SLUG); ?> </label> </th> <td> <input type="text" name="vce[ppp]" value="<?php echo $vce_meta['ppp']; ?> " style="width: 30px;"/> <?php _e('post(s)', THEME_SLUG); ?> <br/> <small class="description"><?php _e('Note: leave empty if you want to inherit from global category option', THEME_SLUG); ?> </small> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label><?php _e('Starter posts layout', THEME_SLUG); ?> </label> </th> <td> <ul class="vce-img-select-wrap next-hide"> <?php foreach ($starter_layouts as $id => $layout) { ?> <li> <?php $selected_class = vce_compare($vce_meta['top_layout'], $id) ? ' selected' : ''; ?> <img src="<?php echo $layout['img']; ?> " title="<?php echo $layout['title']; ?> " class="vce-img-select<?php echo $selected_class; ?> "> <input type="radio" class="vce-hidden" name="vce[top_layout]" value="<?php echo $id; ?> " <?php checked($id, $vce_meta['top_layout']); ?> /> </label> </li> <?php } ?> </ul> <p class="description"><?php _e('Check if you want to use starter posts', THEME_SLUG); ?> </p> </td> </tr> <?php $style = $vce_meta['top_layout'] == 'inherit' || !$vce_meta['top_layout'] ? 'style="display:none"' : ''; ?> <tr class="form-field" <?php echo $style; ?> > <th scope="row" valign="top"> <label><?php _e('Starter posts limit', THEME_SLUG); ?> </label> </th> <td> <input type="text" name="vce[top_limit]" value="<?php echo $vce_meta['top_limit']; ?> " style="width: 30px;"/> <?php _e('post(s)', THEME_SLUG); ?> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label><?php _e('Sidebar layout', THEME_SLUG); ?> </label> </th> <td> <ul class="vce-img-select-wrap"> <?php foreach ($sidebars_lay as $id => $layout) { ?> <li> <?php $selected_class = vce_compare($vce_meta['use_sidebar'], $id) ? ' selected' : ''; ?> <img src="<?php echo $layout['img']; ?> " title="<?php echo $layout['title']; ?> " class="vce-img-select<?php echo $selected_class; ?> "> <input type="radio" class="vce-hidden" name="vce[use_sidebar]" value="<?php echo $id; ?> " <?php checked($id, $vce_meta['use_sidebar']); ?> /> </label> </li> <?php } ?> </ul> <p class="description"><?php _e('Choose sidebar layout', THEME_SLUG); ?> </p> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label><?php _e('Standard sidebar', THEME_SLUG); ?> </label> </th> <td> <select name="vce[sidebar]" class="widefat"> <?php foreach ($sidebars as $id => $name) { ?> <option value="<?php echo $id; ?> " <?php selected($id, $vce_meta['sidebar']); ?> ><?php echo $name; ?> </option> <?php } ?> </select> <p class="description"><?php _e('Choose standard sidebar to display', THEME_SLUG); ?> </p> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label><?php _e('Sticky sidebar', THEME_SLUG); ?> </label> </th> <td> <select name="vce[sticky_sidebar]" class="widefat"> <?php foreach ($sidebars as $id => $name) { ?> <option value="<?php echo $id; ?> " <?php selected($id, $vce_meta['sticky_sidebar']); ?> ><?php echo $name; ?> </option> <?php } ?> </select> <p class="description"><?php _e('Choose sticky sidebar to display', THEME_SLUG); ?> </p> </td> </tr> <?php $most_used = get_option('vce_recent_cat_colors'); $colors = ''; if (!empty($most_used)) { $colors .= '<p>' . __('Recently used', THEME_SLUG) . ': <br/>'; foreach ($most_used as $color) { $colors .= '<a href="#" style="width: 20px; height: 20px; background: ' . $color . '; float: left; margin-right:3px; border: 1px solid #aaa;" class="vce_colorpick" data-color="' . $color . '"></a>'; } $colors .= '</p>'; } ?> <tr class="form-field"> <th scope="row" valign="top"><label><?php _e('Color', THEME_SLUG); ?> </label></th> <td> <label><input type="radio" name="vce[color_type]" value="inherit" class="vce-radio color-type" <?php checked($vce_meta['color_type'], 'inherit'); ?> > <?php _e('Inherit from default accent color', THEME_SLUG); ?> </label> <br/> <label><input type="radio" name="vce[color_type]" value="custom" class="vce-radio color-type" <?php checked($vce_meta['color_type'], 'custom'); ?> > <?php _e('Custom', THEME_SLUG); ?> </label> <div id="vce_color_wrap"> <p> <input name="vce[color]" type="text" class="vce_colorpicker" value="<?php echo $vce_meta['color']; ?> " data-default-color="<?php echo $vce_meta['color']; ?> "/> </p> <?php if (!empty($colors)) { echo $colors; } ?> </div> <div class="clear"></div> <p class="howto"><?php _e('Choose color', THEME_SLUG); ?> </p> </td> </tr> <?php }
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 ($time_diff = vce_get_option('category_fa_time')) { $q_args['date_query'] = array('after' => date('Y-m-d', strtotime($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; }