prefix = framework_get_prefix();
/* Set up the widget options. */
$widget_options = array(
'classname' => 'categories',
'description' => esc_html__( 'A list of your site\'s categories.', 'wordsmith' )
);
/* Set up the widget control options. */
$control_options = array(
'width' => 525,
'height' => 350
);
/* Create the widget. */
$this->WP_Widget( "{$this->prefix}-categories", __( 'Categories', 'wordsmith' ), $widget_options, $control_options );
}
/* Outputs the widget based on the arguments input through the widget controls. */
function widget( $args, $instance ) {
extract( $args );
/* Arguments for the widget. */
$args = array( 'echo' => false, 'depth' => 1, 'show_count' => true, 'style' => 'list', 'title_li' => false );
$args['taxonomy'] = $instance['taxonomy'];
$args['orderby'] = $instance['orderby'];
$args['order'] = $instance['order'];
$args['include'] = ( is_array( $instance['include'] ) ? join( ', ', $instance['include'] ) : $instance['include'] );
$args['exclude'] = ( is_array( $instance['exclude'] ) ? join( ', ', $instance['exclude'] ) : $instance['exclude'] );
$args['number'] = intval( $instance['number'] );
/* Output the theme's $before_widget wrapper. */
echo $before_widget;
/* If a title was input by the user, display it. */
if ( !empty( $instance['title'] ) )
echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title;
/* Get the categories list. */
$categories = str_replace( array( '\r', '\n', '\t' ), '', wp_list_categories( $args ) );
$categories = str_replace( '(', '', $categories );
$categories = str_replace( ')', '', $categories );
echo '
';
echo $categories;
echo '
';
/* Close the theme's widget wrapper. */
echo $after_widget;
}
/* Updates the widget control options for the particular instance of the widget. */
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance = $new_instance;
if ( $instance['taxonomy'] !== $old_instance['taxonomy'] && '' !== $old_instance['taxonomy'] ) {
$instance['include'] = array();
$instance['exclude'] = array();
}
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['taxonomy'] = $new_instance['taxonomy'];
$instance['order'] = $new_instance['order'];
$instance['orderby'] = $new_instance['orderby'];
$instance['number'] = strip_tags( $new_instance['number'] );
$instance['include'] = $new_instance['include'];
$instance['exclude'] = $new_instance['exclude'];
return $instance;
}
/* Displays the widget control options in the Widgets admin screen. */
function form( $instance ) {
/* Set up the default form values. */
$defaults = array(
'title' => esc_attr__( 'Categories', 'wordsmith' ),
'taxonomy' => 'category',
'include' => array(),
'exclude' => array(),
'number' => '5',
'order' => 'ASC',
'orderby' => 'name'
);
/* Merge the user-selected arguments with the defaults. */
$instance = wp_parse_args( (array) $instance, $defaults );
/* Select element options. */
$taxonomies = get_taxonomies( array( 'show_tagcloud' => true ), 'objects' );
$terms = get_terms( $instance['taxonomy'] );
$order = array( 'ASC' => esc_attr__( 'Ascending', 'wordsmith' ), 'DESC' => esc_attr__( 'Descending', 'wordsmith' ) );
$orderby = array( 'count' => esc_attr__( 'Count', 'wordsmith' ), 'ID' => esc_attr__( 'ID', 'wordsmith' ), 'name' => esc_attr__( 'Name', 'wordsmith' ), 'slug' => esc_attr__( 'Slug', 'wordsmith' ), 'term_group' => esc_attr__( 'Term Group', 'wordsmith' ) );
?>