'terms', 'description' => _a("A list of taxonomy terms like categories or post tags")); $control_ops = array('width' => 500); $this->WP_Widget('atom-terms', _a('Terms'), $widget_ops, $control_ops); } /* gets all term ancestors (if taxonomy is hierarchical) */ /* part of the code snatched from: http://core.trac.wordpress.org/attachment/ticket/12443/get_ancestors.2.12443.diff */ /* the complete function should be available in 3.1 */ function get_ancestors($id = 0, $taxonomy = 'category') { $ancestors = array(); if(is_taxonomy_hierarchical($taxonomy)): $term = get_term($id, $taxonomy); while (!is_wp_error($term) && !empty($term->parent) && !in_array($term->parent, $ancestors)): $ancestors[] = (int) $term->parent; $term = get_term($term->parent, $taxonomy); endwhile; endif; return $ancestors; } function template(){ return "\n" ." {NAME} ({POST_COUNT})\n" ." {DESCRIPTION}\n" ."\n"; } function term_entry($category, $args, $depth){ $description = convert_smilies(atom_filter_content(apply_filters('category_description', $category->description, $category), array( 'limit' => intval($args['description_word_limit']), 'allowed_tags' => explode(',', $args['allowed_tags']), 'more' => $args['content_filter_more'] ))); return atom_render_template($args['template'], array( 'NAME' => apply_filters('list_cats', esc_attr($category->name), $category), 'URL' => get_term_link($category, $category->taxonomy), 'POST_COUNT' => intval($category->count), 'DESCRIPTION' => $description, 'ID' => $category->term_id, 'RSS' => !empty($feed) ? get_term_feed_link($category->term_id, $category->taxonomy, $feed_type) : NULL )); } function widget($args, $instance){ global $wp_query; extract($args); $instance = wp_parse_args($instance, $this->defaults()); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); if($instance['type'] == 'sub' && is_taxonomy_hierarchical($instance['taxonomy'])): // only show on pages where the current category is set if (((($instance['taxonomy'] == 'category') && is_category()) || is_tax($instance['taxonomy'] || is_single())) === false) return atom_add_debug_message("Current category doesn't have children categories requested by {$args['widget_id']} ({$args['widget_name']}). Widget marked as inactive"); // $root = get_query_var('cat'); $category = $wp_query->get_queried_object(); $ancestor = end($this->get_ancestors($category->term_id, $instance['taxonomy'])); if($instance['root'] && $ancestor) $root = $ancestor; else $root = $category->term_id; $term = get_term($root, $instance['taxonomy']); $title = ''.$term->name.''; endif; echo $before_widget; if($title) echo $before_title.$title.$after_title; $query_args = array( 'child_of' => isset($root) ? $root : 0, 'orderby' => $instance['order_by'], 'hierarchical' => $instance['hierarchical'] ? '1' : '0', 'taxonomy' => $instance['taxonomy'], 'hide_empty' => $instance['hide_empty'] ? '1' : '0', 'title_li' => '', 'exclude' => $instance['exclude'], 'depth' => $instance['depth'], 'walker' => $instance['dropdown'] ? '' : new atom_walker_terms(), 'link-callback' => array(&$this, 'term_entry'), 'template' => $instance['template'], 'description_word_limit' => $instance['description_word_limit'], 'allowed_tags' => $instance['allowed_tags'], 'content_filter_more' => $instance['content_filter_more'], ); if($instance['order_by'] == 'count') $query_args['order'] = 'DESC'; $tax = get_taxonomy($instance['taxonomy']); if ($instance['dropdown'] ? '1' : '0'): $query_args['show_option_none'] = $tax->label.':'; $query_args['class'] = 'wide'; $query_args['name'] = $this->id.'_terms'; $query_args['id'] = $this->id.'_terms'; wp_dropdown_categories(apply_filters('widget_categories_dropdown_args', $query_args)); ?>
defaults()); } function defaults(){ // default settings return apply_filters('atom_widget_terms_defaults', array( 'title' => _a("Categories"), 'taxonomy' => 'category', 'type' => 'all', 'root' => true, 'dropdown' => 0, 'hierarchical' => 1, 'hide_empty' => 1, 'order_by' => 'name', 'depth' => 0, 'exclude' => '', 'template' => $this->template(), // internal settings 'description_word_limit' => 10, 'allowed_tags' => 'abbr,acronym,b,cite,code,del,dfn,em,i,ins,q,strong,sub,sup', 'content_filter_more' => '[…]', ), $this); } function form($instance){ $instance = wp_parse_args($instance, $this->defaults()); ?>
/>
/>
/>