Advertisement
uabassguy

plugin

Sep 9th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. // Display Taxonomy Widget
  2. function widget( $args, $instance ) {
  3.  
  4. global $post;
  5. extract($args);
  6.  
  7. // Options set in the widget control panel
  8. $taxTitle = apply_filters('arixTaxonomyTitle',$instance['arixTaxonomyTitle']);
  9. $taxType = apply_filters('arixTaxonomyType',$instance['arixTaxonomyType']);
  10. $taxDisplay = apply_filters('arixTaxonomyDisplay',$instance['arixTaxonomyDisplay']);
  11. $taxOrderby = apply_filters('arixTaxonomyOrderby',$instance['arixTaxonomyOrderby']);
  12. $taxOrder = apply_filters('arixTaxonomyOrder',$instance['arixTaxonomyOrder']);
  13. $taxCount = apply_filters('arixTaxonomyCount',$instance['arixTaxonomyCount']);
  14. $taxHidden = apply_filters('arixTaxonomyHidden',$instance['arixTaxonomyHidden']);
  15. $taxSubcats = apply_filters('arixTaxonomySubcats',$instance['arixTaxonomySubcats']);
  16.  
  17. // Default values if no option set.
  18. if ( $taxTitle == '' ) $taxTitle = 'Taxonomy Widget';
  19. if ( $taxCount != 1 ) $taxCount = 0;
  20. if ( $taxHidden != 0 || !isset($taxHidden) ) $taxHidden = 1;
  21.  
  22. if ( $taxSubcats != true || !isset($taxSubcats) ) {
  23. $taxSubcats = "false";
  24. $depth = 1;
  25. } else {
  26. $depth = 0;
  27. }
  28.  
  29. echo $taxPad;
  30.  
  31. echo $before_widget;
  32. $title = $before_title.$taxTitle.$after_title;
  33.  
  34. echo $title;
  35.  
  36. $args = array(
  37. 'taxonomy' => '' . $taxType . '',
  38. 'orderby' => '' . $taxOrderby . '',
  39. 'order' => '' . $taxOrder . '',
  40. 'show_count' => $taxCount,
  41. 'pad_counts' => 1,
  42. 'hierarchical' => $taxSubcats,
  43. 'hide_empty' => $taxHidden,
  44. 'depth' => $depth,
  45. 'id' => $this->get_field_id('cat'),
  46. 'title_li' => '',
  47. );
  48.  
  49.  
  50. switch ( $taxDisplay ) {
  51.  
  52. case "list":
  53.  
  54. echo '<ul>';
  55. wp_list_categories($args);
  56. echo '</ul>';
  57. break;
  58.  
  59. case "dropdown":
  60.  
  61. $terms = get_terms( $taxType, $args );
  62. $catid = $this->get_field_id('cat');
  63. $plugin_url = plugins_url('tax_ajax.js', __FILE__ );
  64. echo "<script src='". $plugin_url ."'></script>";
  65. echo "<script type='text/javascript'>var taxtype = '" . $taxType . "';</script>";
  66.  
  67. echo '<select name="arixDropdown" class="aDropOptions" onchange="element=jQuery(this);fetch_category(element,taxtype);">';
  68.  
  69. echo '<option value="#">Select...</option>';
  70.  
  71. foreach ( $terms as $term ) {
  72.  
  73. $termURL = get_term_link( $term , $termType);
  74.  
  75. if ($term->parent == 0) {
  76.  
  77. echo '<option value="' . $term->term_id . '">' . $term->name . ' (' . $term->count . ')</option>';
  78.  
  79. $termchildren = get_term_children( $term->term_id, $taxType );
  80.  
  81. foreach ( $termchildren as $children ) {
  82.  
  83. $child = get_term_by( 'id', $children, $taxType );
  84. $childURL = get_term_link( $child->slug, $taxType );
  85. $a = get_ancestors( $child->term_id, $taxType );
  86.  
  87. echo '<option value="' . $child->term_id . '">';
  88. foreach ( $a as $spaces ) { echo '-'; }
  89. echo $child->name . ' (' . $child->count . ')</option>';
  90.  
  91. }
  92.  
  93. }
  94.  
  95. }
  96.  
  97. echo '</select>';
  98.  
  99. break;
  100.  
  101. case "tagcloud":
  102. wp_tag_cloud( array(
  103.  
  104. 'order' => '' . $taxOrder . '',
  105. 'taxonomy' => '' . $taxType . ''
  106.  
  107. ) );
  108. break;
  109. }
  110.  
  111. wp_reset_query();
  112. echo $after_widget;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement