WP_Widget_Tag_Cloud::form() WordPress Method
The WP_Widget_Tag_Cloud::form() method is used to display a form for setting the widget options. The form consists of a list of checkboxes, one for each available tag. The tags are displayed in alphabetical order. The user can select which tags to display in the widget by checking the appropriate checkboxes.
WP_Widget_Tag_Cloud::form( array $instance ) #
Outputs the Tag Cloud widget settings form.
Parameters
- $instance
(array)(Required)Current settings.
Source
File: wp-includes/widgets/class-wp-widget-tag-cloud.php
public function form( $instance ) { $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; $count = isset( $instance['count'] ) ? (bool) $instance['count'] : false; ?> <p> <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $title ); ?>" /> </p> <?php $taxonomies = get_taxonomies( array( 'show_tagcloud' => true ), 'object' ); $current_taxonomy = $this->_get_current_taxonomy( $instance ); switch ( count( $taxonomies ) ) { // No tag cloud supporting taxonomies found, display error message. case 0: ?> <input type="hidden" id="<?php echo $this->get_field_id( 'taxonomy' ); ?>" name="<?php echo $this->get_field_name( 'taxonomy' ); ?>" value="" /> <p> <?php _e( 'The tag cloud will not be displayed since there are no taxonomies that support the tag cloud widget.' ); ?> </p> <?php break; // Just a single tag cloud supporting taxonomy found, no need to display a select. case 1: $keys = array_keys( $taxonomies ); $taxonomy = reset( $keys ); ?> <input type="hidden" id="<?php echo $this->get_field_id( 'taxonomy' ); ?>" name="<?php echo $this->get_field_name( 'taxonomy' ); ?>" value="<?php echo esc_attr( $taxonomy ); ?>" /> <?php break; // More than one tag cloud supporting taxonomy found, display a select. default: ?> <p> <label for="<?php echo $this->get_field_id( 'taxonomy' ); ?>"><?php _e( 'Taxonomy:' ); ?></label> <select class="widefat" id="<?php echo $this->get_field_id( 'taxonomy' ); ?>" name="<?php echo $this->get_field_name( 'taxonomy' ); ?>"> <?php foreach ( $taxonomies as $taxonomy => $tax ) : ?> <option value="<?php echo esc_attr( $taxonomy ); ?>" <?php selected( $taxonomy, $current_taxonomy ); ?>> <?php echo esc_html( $tax->labels->name ); ?> </option> <?php endforeach; ?> </select> </p> <?php } if ( count( $taxonomies ) > 0 ) { ?> <p> <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>" <?php checked( $count, true ); ?> /> <label for="<?php echo $this->get_field_id( 'count' ); ?>"><?php _e( 'Show tag counts' ); ?></label> </p> <?php } }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
2.8.0 | Introduced. |