Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/04/2012, 15:14
wayward
(Desactivado)
 
Fecha de Ingreso: enero-2004
Mensajes: 136
Antigüedad: 20 años, 3 meses
Puntos: 0
Categories widget class

Buenas noches.

Estoy tratando de que el widget class no me muestre las subcategorias.

Lo he conseguido introduciendo 'depth=1'

Sin embargo, ya no me aparece como antes la leyenda "Seleccionar categoria", ahora directamente me aparece la primera categoria seleccionada.

¿Alguan idea de como arreglarlo?


Un saludo.
Código PHP:
Ver original
  1. /**
  2.  * Categories widget class
  3.  *
  4.  * @since 2.8.0
  5.  */
  6. class WP_Widget_Categories extends WP_Widget {
  7.  
  8.     function __construct() {
  9.         $widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories" ) );
  10.         parent::__construct('categories', __('Categories'), $widget_ops);
  11.     }
  12.  
  13.     function widget( $args, $instance) {
  14.         extract( $args );
  15.  
  16.         $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base);
  17.         $c = ! empty( $instance['count'] ) ? '1' : '0';
  18.         $h = ! empty( $instance['hierarchical'] ) ? '1' : '0';
  19.         $d = ! empty( $instance['dropdown'] ) ? '1' : '0';
  20.         $x = "96";
  21.        
  22.        
  23.         echo $before_widget;
  24.         if ( $title )
  25.             echo $before_title . $title . $after_title;
  26.  
  27.         $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h, 'depth' => $k, 'exclude' => $x);
  28.  
  29.         if ( $d ) {
  30.             $cat_args['show_option_all'] = __('Select Category');
  31.             wp_dropdown_categories('depth=1', apply_filters('widget_categories_dropdown_args', $cat_args));
  32. ?>
  33.  
  34. <script type='text/javascript'>
  35. /* <![CDATA[ */
  36.     var dropdown = document.getElementById("cat");
  37.     function onCatChange() {
  38.         if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
  39.             location.href = "<?php echo home_url(); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
  40.         }
  41.     }
  42.     dropdown.onchange = onCatChange;
  43. /* ]]> */
  44. </script>
  45.  
  46. <?php
  47.         } else {
  48. ?>
  49.         <ul>
  50. <?php
  51.         $cat_args['title_li'] = '';
  52.         wp_list_categories('depth=1', apply_filters('widget_categories_args', $cat_args));
  53. ?>
  54.         </ul>
  55. <?php
  56.         }
  57.  
  58.         echo $after_widget;
  59.     }
  60.  
  61.     function update( $new_instance, $old_instance ) {
  62.         $instance = $old_instance;
  63.         $instance['title'] = strip_tags($new_instance['title']);
  64.         $instance['count'] = !empty($new_instance['count']) ? 1 : 0;
  65.         $instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0;
  66.         $instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
  67.  
  68.         return $instance;
  69.     }
  70.  
  71.     function form( $instance ) {
  72.         //Defaults
  73.         $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
  74.         $title = esc_attr( $instance['title'] );
  75.         $count = isset($instance['count']) ? (bool) $instance['count'] :false;
  76.         $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
  77.         $dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
  78. ?>
  79.         <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label>
  80.         <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
  81.  
  82.         <p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>"<?php checked( $dropdown ); ?> />
  83.         <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Display as dropdown' ); ?></label><br />
  84.  
  85.         <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> />
  86.         <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e( 'Show post counts' ); ?></label><br />
  87.  
  88.         <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> />
  89.         <label for="<?php echo $this->get_field_id('hierarchical'); ?>"><?php _e( 'Show hierarchy' ); ?></label></p>
  90. <?php
  91.     }
  92.  
  93. }