Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Display Taxonomy Widget
- function widget( $args, $instance ) {
- global $post;
- extract($args);
- // Options set in the widget control panel
- $taxTitle = apply_filters('arixTaxonomyTitle',$instance['arixTaxonomyTitle']);
- $taxType = apply_filters('arixTaxonomyType',$instance['arixTaxonomyType']);
- $taxDisplay = apply_filters('arixTaxonomyDisplay',$instance['arixTaxonomyDisplay']);
- $taxOrderby = apply_filters('arixTaxonomyOrderby',$instance['arixTaxonomyOrderby']);
- $taxOrder = apply_filters('arixTaxonomyOrder',$instance['arixTaxonomyOrder']);
- $taxCount = apply_filters('arixTaxonomyCount',$instance['arixTaxonomyCount']);
- $taxHidden = apply_filters('arixTaxonomyHidden',$instance['arixTaxonomyHidden']);
- $taxSubcats = apply_filters('arixTaxonomySubcats',$instance['arixTaxonomySubcats']);
- // Default values if no option set.
- if ( $taxTitle == '' ) $taxTitle = 'Taxonomy Widget';
- if ( $taxCount != 1 ) $taxCount = 0;
- if ( $taxHidden != 0 || !isset($taxHidden) ) $taxHidden = 1;
- if ( $taxSubcats != true || !isset($taxSubcats) ) {
- $taxSubcats = "false";
- $depth = 1;
- } else {
- $depth = 0;
- }
- echo $taxPad;
- echo $before_widget;
- $title = $before_title.$taxTitle.$after_title;
- echo $title;
- $args = array(
- 'taxonomy' => '' . $taxType . '',
- 'orderby' => '' . $taxOrderby . '',
- 'order' => '' . $taxOrder . '',
- 'show_count' => $taxCount,
- 'pad_counts' => 1,
- 'hierarchical' => $taxSubcats,
- 'hide_empty' => $taxHidden,
- 'depth' => $depth,
- 'id' => $this->get_field_id('cat'),
- 'title_li' => '',
- );
- switch ( $taxDisplay ) {
- case "list":
- echo '<ul>';
- wp_list_categories($args);
- echo '</ul>';
- break;
- case "dropdown":
- $terms = get_terms( $taxType, $args );
- $catid = $this->get_field_id('cat');
- $plugin_url = plugins_url('tax_ajax.js', __FILE__ );
- echo "<script src='". $plugin_url ."'></script>";
- echo "<script type='text/javascript'>var taxtype = '" . $taxType . "';</script>";
- echo '<select name="arixDropdown" class="aDropOptions" onchange="element=jQuery(this);fetch_category(element,taxtype);">';
- echo '<option value="#">Select...</option>';
- foreach ( $terms as $term ) {
- $termURL = get_term_link( $term , $termType);
- if ($term->parent == 0) {
- echo '<option value="' . $term->term_id . '">' . $term->name . ' (' . $term->count . ')</option>';
- $termchildren = get_term_children( $term->term_id, $taxType );
- foreach ( $termchildren as $children ) {
- $child = get_term_by( 'id', $children, $taxType );
- $childURL = get_term_link( $child->slug, $taxType );
- $a = get_ancestors( $child->term_id, $taxType );
- echo '<option value="' . $child->term_id . '">';
- foreach ( $a as $spaces ) { echo '-'; }
- echo $child->name . ' (' . $child->count . ')</option>';
- }
- }
- }
- echo '</select>';
- break;
- case "tagcloud":
- wp_tag_cloud( array(
- 'order' => '' . $taxOrder . '',
- 'taxonomy' => '' . $taxType . ''
- ) );
- break;
- }
- wp_reset_query();
- echo $after_widget;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement