function axiom_callback_admin_change_post_type() { if (!wp_verify_nonce($_REQUEST['nonce'], 'ajax_nonce')) { die; } $post_type = $_REQUEST['post_type']; $terms = axiom_get_list_terms(false, axiom_get_taxonomy_categories_by_post_type($post_type)); $terms = axiom_array_merge(array(0 => __('- Select category -', 'axiom')), $terms); $response = array('error' => '', 'data' => array('ids' => array_keys($terms), 'titles' => array_values($terms))); echo json_encode($response); die; }
/** * Displays the widget settings controls on the widget panel. * Make use of the get_field_id() and get_field_name() function * when creating your form elements. This handles the confusing stuff. */ function form($instance) { // Set up some default widget settings $instance = wp_parse_args((array) $instance, array('title' => '', 'title_author' => '', 'title_users' => '', 'number' => '4', 'show_date' => '1', 'show_image' => '1', 'show_author' => '1', 'show_counters' => '1', 'category' => '0', 'post_type' => 'post')); $title = $instance['title']; $title_author = $instance['title_author']; $title_users = $instance['title_users']; $number = (int) $instance['number']; $show_date = (int) $instance['show_date']; $show_image = (int) $instance['show_image']; $show_author = (int) $instance['show_author']; $show_counters = (int) $instance['show_counters']; $post_type = $instance['post_type']; $category = (int) $instance['category']; $posts_types = axiom_get_list_posts_types(false); $categories = axiom_get_list_terms(false, axiom_get_taxonomy_categories_by_post_type($post_type)); ?> <p> <label for="<?php echo esc_attr($this->get_field_id('title')); ?> "><?php _e('Widget title:', 'axiom'); ?> </label> <input id="<?php echo esc_attr($this->get_field_id('title')); ?> " name="<?php echo esc_attr($this->get_field_name('title')); ?> " value="<?php echo esc_attr($title); ?> " style="width:100%;" /> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('title_author')); ?> "><?php _e('Author rating tab title:', 'axiom'); ?> </label> <input id="<?php echo esc_attr($this->get_field_id('title_author')); ?> " name="<?php echo esc_attr($this->get_field_name('title_author')); ?> " value="<?php echo esc_attr($title_author); ?> " style="width:100%;" /> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('title_users')); ?> "><?php _e('Users rating tab title:', 'axiom'); ?> </label> <input id="<?php echo esc_attr($this->get_field_id('title_users')); ?> " name="<?php echo esc_attr($this->get_field_name('title_users')); ?> " value="<?php echo esc_attr($title_users); ?> " style="width:100%;" /> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('post_type')); ?> "><?php _e('Post type:', 'axiom'); ?> </label> <select id="<?php echo esc_attr($this->get_field_id('post_type')); ?> " name="<?php echo esc_attr($this->get_field_name('post_type')); ?> " style="width:100%;" onchange="axiom_admin_change_post_type(this);"> <?php foreach ($posts_types as $type => $type_name) { echo '<option value="' . esc_attr($type) . '"' . ($post_type == $type ? ' selected="selected"' : '') . '>' . esc_html($type_name) . '</option>'; } ?> </select> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('category')); ?> "><?php _e('Category:', 'axiom'); ?> </label> <select id="<?php echo esc_attr($this->get_field_id('category')); ?> " name="<?php echo esc_attr($this->get_field_name('category')); ?> " style="width:100%;"> <option value="0"><?php _e('-- Any category --', 'axiom'); ?> </option> <?php foreach ($categories as $cat_id => $cat_name) { echo '<option value="' . esc_attr($cat_id) . '"' . ($category == $cat_id ? ' selected="selected"' : '') . '>' . esc_html($cat_name) . '</option>'; } ?> </select> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('number')); ?> "><?php _e('Number posts to show:', 'axiom'); ?> </label> <input type="text" id="<?php echo esc_attr($this->get_field_id('number')); ?> " name="<?php echo esc_attr($this->get_field_name('number')); ?> " value="<?php echo esc_attr($number); ?> " style="width:100%;" /> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('show_image')); ?> _1"><?php _e('Show post image:', 'axiom'); ?> </label><br /> <input type="radio" id="<?php echo esc_attr($this->get_field_id('show_image')); ?> _1" name="<?php echo esc_attr($this->get_field_name('show_image')); ?> " value="1" <?php echo $show_image == 1 ? ' checked="checked"' : ''; ?> /> <label for="<?php echo esc_attr($this->get_field_id('show_image')); ?> _1"><?php _e('Show', 'axiom'); ?> </label> <input type="radio" id="<?php echo esc_attr($this->get_field_id('show_image')); ?> _0" name="<?php echo esc_attr($this->get_field_name('show_image')); ?> " value="0" <?php echo $show_image == 0 ? ' checked="checked"' : ''; ?> /> <label for="<?php echo esc_attr($this->get_field_id('show_image')); ?> _0"><?php _e('Hide', 'axiom'); ?> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('show_author')); ?> _1"><?php _e('Show post author:', 'axiom'); ?> </label><br /> <input type="radio" id="<?php echo esc_attr($this->get_field_id('show_author')); ?> _1" name="<?php echo esc_attr($this->get_field_name('show_author')); ?> " value="1" <?php echo $show_author == 1 ? ' checked="checked"' : ''; ?> /> <label for="<?php echo esc_attr($this->get_field_id('show_author')); ?> _1"><?php _e('Show', 'axiom'); ?> </label> <input type="radio" id="<?php echo esc_attr($this->get_field_id('show_author')); ?> _0" name="<?php echo esc_attr($this->get_field_name('show_author')); ?> " value="0" <?php echo $show_author == 0 ? ' checked="checked"' : ''; ?> /> <label for="<?php echo esc_attr($this->get_field_id('show_author')); ?> _0"><?php _e('Hide', 'axiom'); ?> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('show_date')); ?> _1"><?php _e('Show post date:', 'axiom'); ?> </label><br /> <input type="radio" id="<?php echo esc_attr($this->get_field_id('show_date')); ?> _1" name="<?php echo esc_attr($this->get_field_name('show_date')); ?> " value="1" <?php echo $show_date == 1 ? ' checked="checked"' : ''; ?> /> <label for="<?php echo esc_attr($this->get_field_id('show_date')); ?> _1"><?php _e('Show', 'axiom'); ?> </label> <input type="radio" id="<?php echo esc_attr($this->get_field_id('show_date')); ?> _0" name="<?php echo esc_attr($this->get_field_name('show_date')); ?> " value="0" <?php echo $show_date == 0 ? ' checked="checked"' : ''; ?> /> <label for="<?php echo esc_attr($this->get_field_id('show_date')); ?> _0"><?php _e('Hide', 'axiom'); ?> </label> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('show_counters')); ?> _1"><?php _e('Show post counters:', 'axiom'); ?> </label><br /> <input type="radio" id="<?php echo esc_attr($this->get_field_id('show_counters')); ?> _2" name="<?php echo esc_attr($this->get_field_name('show_counters')); ?> " value="2" <?php echo $show_counters == 2 ? ' checked="checked"' : ''; ?> /> <label for="<?php echo esc_attr($this->get_field_id('show_counters')); ?> _2"><?php _e('As stars', 'axiom'); ?> </label> <input type="radio" id="<?php echo esc_attr($this->get_field_id('show_counters')); ?> _1" name="<?php echo esc_attr($this->get_field_name('show_counters')); ?> " value="1" <?php echo $show_counters == 1 ? ' checked="checked"' : ''; ?> /> <label for="<?php echo esc_attr($this->get_field_id('show_counters')); ?> _1"><?php _e('As icon', 'axiom'); ?> </label> <input type="radio" id="<?php echo esc_attr($this->get_field_id('show_counters')); ?> _0" name="<?php echo $this->get_field_name('show_counters'); ?> " value="0" <?php echo $show_counters == 0 ? ' checked="checked"' : ''; ?> /> <label for="<?php echo esc_attr($this->get_field_id('show_counters')); ?> _0"><?php _e('Hide', 'axiom'); ?> </label> </p> <?php }
function axiom_sc_slider($atts, $content = null) { if (axiom_sc_in_shortcode_blogger()) { return ''; } extract(axiom_sc_html_decode(shortcode_atts(array("engine" => axiom_get_custom_option('substitute_slider_engine'), "custom" => "no", "alias" => "", "post_type" => "post", "ids" => "", "cat" => "", "count" => "0", "offset" => "", "orderby" => "date", "order" => 'desc', "controls" => "no", "pagination" => "no", "titles" => "no", "descriptions" => axiom_get_custom_option('slider_info_descriptions'), "links" => "no", "align" => "", "interval" => "", "date_format" => "", "crop" => "yes", "autoheight" => "no", "id" => "", "class" => "", "animation" => "", "css" => "", "width" => "", "height" => "", "top" => "", "bottom" => "", "left" => "", "right" => ""), $atts))); if (empty($width) && $pagination != 'full') { $width = "100%"; } if (empty($height) && ($pagination == 'full' || $pagination == 'over')) { $height = 250; } if (!empty($height) && axiom_sc_param_is_on($autoheight)) { $autoheight = "off"; } if (empty($interval)) { $interval = mt_rand(5000, 10000); } global $AXIOM_GLOBALS; $AXIOM_GLOBALS['sc_slider_engine'] = $engine; $AXIOM_GLOBALS['sc_slider_width'] = axiom_prepare_css_value($width); $AXIOM_GLOBALS['sc_slider_height'] = axiom_prepare_css_value($height); $AXIOM_GLOBALS['sc_slider_links'] = axiom_sc_param_is_on($links); $AXIOM_GLOBALS['sc_slider_bg_image'] = false; $AXIOM_GLOBALS['sc_slider_crop_image'] = $crop; if (empty($id)) { $id = "sc_slider_" . str_replace('.', '', mt_rand()); } $ms = axiom_get_css_position_from_values($top, $right, $bottom, $left); $ws = axiom_get_css_position_from_values('', '', '', '', $width); $hs = axiom_get_css_position_from_values('', '', '', '', '', $height); $css .= (!in_array($pagination, array('full', 'over')) ? $ms : '') . $hs . $ws; if ($engine != 'swiper' && in_array($pagination, array('full', 'over'))) { $pagination = 'yes'; } $output = (in_array($pagination, array('full', 'over')) ? '<div class="sc_slider_pagination_area sc_slider_pagination_' . esc_attr($pagination) . ($align != '' && $align != 'none' ? ' align' . esc_attr($align) : '') . '"' . (!axiom_sc_param_is_off($animation) ? ' data-animation="' . esc_attr(axiom_sc_get_animation_classes($animation)) . '"' : '') . ($ms . $hs ? ' style="' . esc_attr($ms . $hs) . '"' : '') . '>' : '') . '<div' . ($id ? ' id="' . esc_attr($id) . '"' : '') . ' class="sc_slider sc_slider_' . esc_attr($engine) . ($engine == 'swiper' ? ' swiper-slider-container' : '') . (!empty($class) ? ' ' . esc_attr($class) : '') . (axiom_sc_param_is_on($autoheight) ? ' sc_slider_height_auto' : '') . ($hs ? ' sc_slider_height_fixed' : '') . (axiom_sc_param_is_on($controls) ? ' sc_slider_controls' : ' sc_slider_nocontrols') . (axiom_sc_param_is_on($pagination) ? ' sc_slider_pagination' : ' sc_slider_nopagination') . (!in_array($pagination, array('full', 'over')) && $align != '' && $align != 'none' ? ' align' . esc_attr($align) : '') . '"' . (!in_array($pagination, array('full', 'over')) && !axiom_sc_param_is_off($animation) ? ' data-animation="' . esc_attr(axiom_sc_get_animation_classes($animation)) . '"' : '') . (!empty($width) && axiom_strpos($width, '%') === false ? ' data-old-width="' . esc_attr($width) . '"' : '') . (!empty($height) && axiom_strpos($height, '%') === false ? ' data-old-height="' . esc_attr($height) . '"' : '') . ((int) $interval > 0 ? ' data-interval="' . esc_attr($interval) . '"' : '') . ($css != '' ? ' style="' . esc_attr($css) . '"' : '') . '>'; axiom_enqueue_slider($engine); if ($engine == 'revo') { if (axiom_exists_revslider() && !empty($alias)) { $output .= do_shortcode('[rev_slider ' . esc_attr($alias) . ']'); } else { $output = ''; } } else { if ($engine == 'swiper') { $caption = ''; $output .= '<div class="slides' . ($engine == 'swiper' ? ' swiper-wrapper' : '') . '"' . ($engine == 'swiper' && $AXIOM_GLOBALS['sc_slider_bg_image'] ? ' style="' . esc_attr($hs) . '"' : '') . '>'; $content = do_shortcode($content); if (axiom_sc_param_is_on($custom) && $content) { $output .= $content; } else { global $post; if (!empty($ids)) { $posts = explode(',', $ids); $count = count($posts); } $args = array('post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => $count, 'ignore_sticky_posts' => 1, 'order' => $order == 'asc' ? 'asc' : 'desc'); if ($offset > 0 && empty($ids)) { $args['offset'] = $offset; } $args = axiom_query_add_sort_order($args, $orderby, $order); $args = axiom_query_add_filters($args, 'thumbs'); $args = axiom_query_add_posts_and_cats($args, $ids, $post_type, $cat); $query = new WP_Query($args); $post_number = 0; $pagination_items = ''; $show_image = 1; $show_types = 0; $show_date = 1; $show_author = 0; $show_links = 0; $show_counters = 'views'; //comments | rating while ($query->have_posts()) { $query->the_post(); $post_number++; $post_id = get_the_ID(); $post_type = get_post_type(); $post_title = get_the_title(); $post_link = get_permalink(); $post_link2 = $post_link; $post_date = get_the_date(!empty($date_format) ? $date_format : 'd.m.y'); $post_attachment = wp_get_attachment_url(get_post_thumbnail_id($post_id)); if (axiom_sc_param_is_on($crop)) { $post_attachment = $AXIOM_GLOBALS['sc_slider_bg_image'] ? axiom_get_resized_image_url($post_attachment, !empty($width) && (double) $width . ' ' == $width . ' ' ? $width : null, !empty($height) && (double) $height . ' ' == $height . ' ' ? $height : null) : axiom_get_resized_image_tag($post_attachment, !empty($width) && (double) $width . ' ' == $width . ' ' ? $width : null, !empty($height) && (double) $height . ' ' == $height . ' ' ? $height : null); } else { if (!$AXIOM_GLOBALS['sc_slider_bg_image']) { $post_attachment = '<img src="' . esc_url($post_attachment) . '" alt="">'; } } $post_accent_color = ''; $post_category = ''; $post_category_link = ''; if (in_array($pagination, array('full', 'over'))) { $old_output = $output; $output = ''; require axiom_get_file_dir('templates/parts/widgets-posts.php'); $pagination_items .= $output; $output = $old_output; } $output .= '<div' . ' class="' . esc_attr($engine) . '-slide"' . ' data-style="' . esc_attr($ws . $hs) . '"' . ' style="' . ($AXIOM_GLOBALS['sc_slider_bg_image'] ? 'background-image:url(' . esc_url($post_attachment) . ');' : '') . $ws . $hs . '"' . '>' . (axiom_sc_param_is_on($links) ? '<a href="' . esc_url($post_link2) . '" title="' . esc_attr($post_title) . '">' : '') . (!$AXIOM_GLOBALS['sc_slider_bg_image'] ? $post_attachment : ''); $caption = $engine == 'swiper' ? '' : $caption; if (!axiom_sc_param_is_off($titles)) { $post_hover_bg = axiom_get_custom_option('link_color', null, $post_id); $post_bg = ''; if ($post_hover_bg != '' && !axiom_is_inherit_option($post_hover_bg)) { $rgb = axiom_hex2rgb($post_hover_bg); $post_hover_ie = str_replace('#', '', $post_hover_bg); $post_bg = "background-color: rgba({$rgb['r']},{$rgb['g']},{$rgb['b']},0.8);"; } $caption .= '<div class="sc_slider_info' . ($titles == 'fixed' ? ' sc_slider_info_fixed' : '') . ($engine == 'swiper' ? ' content-slide' : '') . '"' . ($post_bg != '' ? ' style="' . esc_attr($post_bg) . '"' : '') . '>'; $post_descr = axiom_get_post_excerpt(); if (axiom_get_custom_option("slider_info_category") == 'yes') { // || empty($cat)) { // Get all post's categories $post_tax = axiom_get_taxonomy_categories_by_post_type($post_type); if (!empty($post_tax)) { $post_terms = axiom_get_terms_by_post_id(array('post_id' => $post_id, 'taxonomy' => $post_tax)); if (!empty($post_terms[$post_tax])) { if (!empty($post_terms[$post_tax]->closest_parent)) { $post_category = $post_terms[$post_tax]->closest_parent->name; $post_category_link = $post_terms[$post_tax]->closest_parent->link; //$post_accent_color = axiom_taxonomy_get_inherited_property($post_tax, $post_terms[$post_tax]->closest_parent->term_id, 'link_color'); } /* if ($post_accent_color == '' && !empty($post_terms[$post_tax]->terms)) { for ($i = 0; $i < count($post_terms[$post_tax]->terms); $i++) { $post_accent_color = axiom_taxonomy_get_inherited_property($post_tax, $post_terms[$post_tax]->terms[$i]->term_id, 'link_color'); if ($post_accent_color != '') break; } } */ if ($post_category != '') { $caption .= '<div class="sc_slider_category"' . (axiom_substr($post_accent_color, 0, 1) == '#' ? ' style="background-color: ' . esc_attr($post_accent_color) . '"' : '') . '><a href="' . esc_url($post_category_link) . '">' . $post_category . '</a></div>'; } } } } $output_reviews = ''; if (axiom_get_custom_option('show_reviews') == 'yes' && axiom_get_custom_option('slider_info_reviews') == 'yes') { $avg_author = axiom_reviews_marks_to_display(get_post_meta($post_id, 'reviews_avg' . (axiom_get_theme_option('reviews_first') == 'author' && $orderby != 'users_rating' || $orderby == 'author_rating' ? '' : '2'), true)); if ($avg_author > 0) { $output_reviews .= '<div class="sc_slider_reviews post_rating reviews_summary blog_reviews' . (axiom_get_custom_option("slider_info_category") == 'yes' ? ' after_category' : '') . '">' . '<div class="criteria_summary criteria_row">' . trim(axiom_reviews_get_summary_stars($avg_author, false, false, 5)) . '</div>' . '</div>'; } } if (axiom_get_custom_option("slider_info_category") == 'yes') { $caption .= $output_reviews; } $caption .= '<h3 class="sc_slider_subtitle"><a href="' . esc_url($post_link2) . '">' . $post_title . '</a></h3>'; if (axiom_get_custom_option("slider_info_category") != 'yes') { $caption .= $output_reviews; } if ($descriptions > 0) { $caption .= '<div class="sc_slider_descr">' . trim(axiom_strshort($post_descr, $descriptions)) . '</div>'; } $caption .= '</div>'; } $output .= ($engine == 'swiper' ? $caption : '') . (axiom_sc_param_is_on($links) ? '</a>' : '') . '</div>'; } wp_reset_postdata(); } $output .= '</div>'; if ($engine == 'swiper') { if (axiom_sc_param_is_on($controls)) { $output .= '<div class="sc_slider_controls_wrap"><a class="sc_slider_prev" href="#"></a><a class="sc_slider_next" href="#"></a></div>'; } if (axiom_sc_param_is_on($pagination)) { $output .= '<div class="sc_slider_pagination_wrap"></div>'; } } } else { $output = ''; } } if (!empty($output)) { $output .= '</div>'; if (!isset($pagination_items)) { $pagination_items = ''; } if ($pagination_items) { $output .= ' <div class="sc_slider_pagination widget_area"' . ($hs ? ' style="' . esc_attr($hs) . '"' : '') . '> <div id="' . esc_attr($id) . '_scroll" class="sc_scroll sc_scroll_vertical swiper-slider-container scroll-container"' . ($hs ? ' style="' . esc_attr($hs) . '"' : '') . '> <div class="sc_scroll_wrapper swiper-wrapper"> <div class="sc_scroll_slide swiper-slide"> ' . $pagination_items . ' </div> </div> <div id="' . esc_attr($id) . '_scroll_bar" class="sc_scroll_bar sc_scroll_bar_vertical"></div> </div> </div>'; $output .= '</div>'; } } return apply_filters('axiom_shortcode_output', $output, 'trx_slider', $atts, $content); }
function axiom_get_custom_option($name, $defa = null, $post_id = 0, $post_type = 'post', $tax_id = 0, $tax_type = 'category') { if (isset($_GET[$name])) { $rez = $_GET[$name]; } else { global $AXIOM_GLOBALS; $hash_name = $name . '_' . $tax_id . '_' . $post_id; if (!empty($AXIOM_GLOBALS['theme_options_loaded']) && isset($AXIOM_GLOBALS['custom_options'][$hash_name])) { $rez = $AXIOM_GLOBALS['custom_options'][$hash_name]; } else { if ($tax_id > 0) { $rez = axiom_taxonomy_get_inherited_property($tax_type, $tax_id, $name); if ($rez == '') { $rez = axiom_get_theme_option($name, $defa); } } else { if ($post_id > 0) { $rez = axiom_get_theme_option($name, $defa); $custom_options = get_post_meta($post_id, 'post_custom_options', true); if (isset($custom_options[$name]) && !axiom_is_inherit_option($custom_options[$name])) { $rez = $custom_options[$name]; } else { $terms = array(); $tax = axiom_get_taxonomy_categories_by_post_type($post_type); $tax_obj = get_taxonomy($tax); $tax_query = !empty($tax_obj->query_var) ? $tax_obj->query_var : $tax; if ($tax == 'category' && is_category() || $tax == 'post_tag' && is_tag() || is_tax($tax)) { // Current page is taxonomy's archive (Categories and Tags need specific check) $terms = array(get_queried_object()); } else { $taxes = axiom_get_terms_by_post_id(array('post_id' => $post_id, 'taxonomy' => $tax)); if (!empty($taxes[$tax]->terms)) { $terms = $taxes[$tax]->terms; } } $tmp = ''; if (!empty($terms)) { for ($cc = 0; $cc < count($terms) && (empty($tmp) || axiom_is_inherit_option($tmp)); $cc++) { $tmp = axiom_taxonomy_get_inherited_property($terms[$cc]->taxonomy, $terms[$cc]->term_id, $name); } } if ($tmp != '') { $rez = $tmp; } } } else { $rez = axiom_get_theme_option($name, $defa); if (axiom_get_theme_option('show_theme_customizer') == 'yes' && axiom_get_theme_option('remember_visitors_settings') == 'yes' && function_exists('axiom_get_value_gpc')) { $tmp = axiom_get_value_gpc($name, $rez); if (!axiom_is_inherit_option($tmp)) { $rez = $tmp; } } if (isset($AXIOM_GLOBALS['template_options'][$name]) && !axiom_is_inherit_option($AXIOM_GLOBALS['template_options'][$name])) { $rez = is_array($AXIOM_GLOBALS['template_options'][$name]) ? $AXIOM_GLOBALS['template_options'][$name][0] : $AXIOM_GLOBALS['template_options'][$name]; } if (isset($AXIOM_GLOBALS['taxonomy_options'][$name]) && !axiom_is_inherit_option($AXIOM_GLOBALS['taxonomy_options'][$name])) { $rez = $AXIOM_GLOBALS['taxonomy_options'][$name]; } if (isset($AXIOM_GLOBALS['post_options'][$name]) && !axiom_is_inherit_option($AXIOM_GLOBALS['post_options'][$name])) { $rez = is_array($AXIOM_GLOBALS['post_options'][$name]) ? $AXIOM_GLOBALS['post_options'][$name][0] : $AXIOM_GLOBALS['post_options'][$name]; } } } $rez = apply_filters('axiom_filter_get_custom_option', $rez, $name); if (!empty($AXIOM_GLOBALS['theme_options_loaded'])) { $AXIOM_GLOBALS['custom_options'][$hash_name] = $rez; } } } return $rez; }
function axiom_query_add_posts_and_cats($args, $ids = '', $post_type = '', $cat = '', $taxonomy = '') { if (!empty($ids)) { $args['post_type'] = empty($args['post_type']) ? empty($post_type) ? array('post', 'page') : $post_type : $args['post_type']; $args['post__in'] = explode(',', str_replace(' ', '', $ids)); } else { $args['post_type'] = empty($args['post_type']) ? empty($post_type) ? 'post' : $post_type : $args['post_type']; $post_type = is_array($args['post_type']) ? $args['post_type'][0] : $args['post_type']; if (!empty($cat)) { $cats = !is_array($cat) ? explode(',', $cat) : $cat; if (empty($taxonomy)) { $taxonomy = axiom_get_taxonomy_categories_by_post_type($post_type); } if ($taxonomy == 'category') { // Add standard categories if (count($cats) > 1) { $cats_ids = array(); foreach ($cats as $c) { $c = trim(chop($c)); if (empty($c)) { continue; } if ((int) $c == 0) { $cat_term = get_term_by('slug', $c, $taxonomy, OBJECT); if ($cat_term) { $c = $cat_term->term_id; } } if ($c == 0) { continue; } $cats_ids[] = (int) $c; $children = get_categories(array('type' => $post_type, 'child_of' => $c, 'hide_empty' => 0, 'hierarchical' => 0, 'taxonomy' => $taxonomy, 'pad_counts' => false)); foreach ($children as $c) { if (!in_array((int) $c->term_id, $cats_ids)) { $cats_ids[] = (int) $c->term_id; } } } if (count($cats_ids) > 0) { $args['category__in'] = $cats_ids; } } else { if ((int) $cat > 0) { $args['cat'] = (int) $cat; } else { $args['category_name'] = $cat; } } } else { // Add custom taxonomies if (!isset($args['tax_query'])) { $args['tax_query'] = array(); } $args['tax_query']['relation'] = 'AND'; $args['tax_query'][] = array('taxonomy' => $taxonomy, 'include_children' => true, 'field' => (int) $cats[0] > 0 ? 'id' : 'slug', 'terms' => $cats); } } } return $args; }
/** * Displays the widget settings controls on the widget panel. * Make use of the get_field_id() and get_field_name() function * when creating your form elements. This handles the confusing stuff. */ function form($instance) { // Set up some default widget settings $instance = wp_parse_args((array) $instance, array('title' => '', 'count' => 0, 'dropdown' => 0, 'hierarchical' => 0, 'root' => 0, 'post_type' => 'post')); $title = $instance['title']; $root = (int) $instance['root']; $post_type = $instance['post_type']; $count = (bool) $instance['count']; $hierarchical = (bool) $instance['hierarchical']; $dropdown = (bool) $instance['dropdown']; $posts_types = axiom_get_list_posts_types(false); $categories = axiom_get_list_terms(false, axiom_get_taxonomy_categories_by_post_type($post_type)); ?> <p> <label for="<?php echo esc_attr($this->get_field_id('title')); ?> "><?php _e('Title:', 'axiom'); ?> </label> <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?> " name="<?php echo esc_attr($this->get_field_name('title')); ?> " type="text" value="<?php echo esc_attr($title); ?> " /> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('post_type')); ?> "><?php _e('Post type:', 'axiom'); ?> </label> <select id="<?php echo esc_attr($this->get_field_id('post_type')); ?> " name="<?php echo esc_attr($this->get_field_name('post_type')); ?> " style="width:100%;" onchange="axiom_admin_change_post_type(this);"> <?php foreach ($posts_types as $type => $type_name) { echo '<option value="' . esc_attr($type) . '"' . ($post_type == $type ? ' selected="selected"' : '') . '>' . esc_html($type_name) . '</option>'; } ?> </select> </p> <p> <label for="<?php echo esc_attr($this->get_field_id('root')); ?> "><?php _e('Root category:', 'axiom'); ?> </label> <select id="<?php echo esc_attr($this->get_field_id('root')); ?> " name="<?php echo esc_attr($this->get_field_name('root')); ?> " style="width:100%;"> <option value="0"><?php _e('-- Any category --', 'axiom'); ?> </option> <?php foreach ($categories as $cat_id => $cat_name) { echo '<option value="' . esc_attr($cat_id) . '"' . ($root == $cat_id ? ' selected="selected"' : '') . '>' . $cat_name . '</option>'; } ?> </select> </p> <p> <input type="checkbox" class="checkbox" id="<?php echo esc_attr($this->get_field_id('dropdown')); ?> " name="<?php echo esc_attr($this->get_field_name('dropdown')); ?> "<?php checked($dropdown); ?> /> <label for="<?php echo esc_attr($this->get_field_id('dropdown')); ?> "><?php _e('Display as dropdown', 'axiom'); ?> </label><br /> <input type="checkbox" class="checkbox" id="<?php echo esc_attr($this->get_field_id('count')); ?> " name="<?php echo esc_attr($this->get_field_name('count')); ?> "<?php checked($count); ?> /> <label for="<?php echo esc_attr($this->get_field_id('count')); ?> "><?php _e('Show post counts', 'axiom'); ?> </label><br /> <input type="checkbox" class="checkbox" id="<?php echo esc_attr($this->get_field_id('hierarchical')); ?> " name="<?php echo esc_attr($this->get_field_name('hierarchical')); ?> "<?php checked($hierarchical); ?> /> <label for="<?php echo esc_attr($this->get_field_id('hierarchical')); ?> "><?php _e('Show hierarchy', 'axiom'); ?> </label> </p> <?php }