AnsPress_Category_Widget::form( $instance )

Description #

Source #

File: addons/free/category/widget.php

	public function form( $instance ) {
		$title = ! empty( $instance[ 'title' ] ) ? $instance[ 'title' ] : __( 'Categories', 'anspress-question-answer' );
		$hide_empty = ! empty( $instance[ 'hide_empty' ] ) ? $instance[ 'hide_empty' ] : false;
		$parent = ! empty( $instance[ 'parent' ] ) ? $instance[ 'parent' ] : 0;
		$number = ! empty( $instance[ 'number' ] ) ? $instance[ 'number' ] : 10;
		$orderby = ! empty( $instance[ 'orderby' ] ) ? $instance[ 'orderby' ] : 'count';
		$order = ! empty( $instance[ 'order' ] ) ? $instance[ 'order' ] : 'DESC';
		$icon_height = ! empty( $instance[ 'icon_height' ] ) ? $instance[ 'icon_height' ] : '32';
		$icon_width = ! empty( $instance[ 'icon_width' ] ) ? $instance[ 'icon_width' ] : '32';

		$cat_args = array(
			'hide_empty'    => false,
			'orderby'       => 'count',
			'order'         => 'DESC',
		);

		$categories = get_terms( 'question_category' , $cat_args );
		?>
		<p>
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'anspress-question-answer' ); ?></label>
			<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>"
			  type="text" value="<?php echo esc_attr( $title ); ?>">
		</p>
		<p>
			<label for="<?php echo $this->get_field_id( 'hide_empty' ); ?>"><?php _e( 'Hide empty:', 'anspress-question-answer' ); ?></label>
			<input class="widefat" id="<?php echo $this->get_field_id( 'hide_empty' ); ?>" name="<?php echo $this->get_field_name( 'hide_empty' ); ?>"
			  type="checkbox" value="1" <?php checked( true, $hide_empty );?>>
		</p>
		<p>
			<label for="<?php echo $this->get_field_id( 'parent' ); ?>"><?php _e( 'Parent:', 'anspress-question-answer' ); ?></label>
			<select class="widefat" id="<?php echo $this->get_field_id( 'parent' ); ?>" name="<?php echo $this->get_field_name( 'parent' ); ?>">
				<option value="0"><?php _e('Top level', 'anspress-question-answer' ); ?></option>
				<?php
				if ( $categories ) {
					foreach ( $categories as $c ) {
						echo '<option value="'.$c->term_id.'" '.selected($parent, $c->term_id ).'>'.$c->name.'</option>'; }
				}

				?>
            </select>
		</p>
		<p>
			<label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number:', 'anspress-question-answer' ); ?></label>
			<input class="widefat" id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>"
			  type="text" value="<?php echo esc_attr( $number ); ?>">
		</p>
		<p>
			<label for="<?php echo $this->get_field_id( 'orderby' ); ?>"><?php _e( 'Order By:', 'anspress-question-answer' ); ?></label>
			<select class="widefat" id="<?php echo $this->get_field_id( 'orderby' ); ?>" name="<?php echo $this->get_field_name( 'orderby' ); ?>">
				<option value="none" <?php echo selected($orderby, 'none' ); ?>><?php _e('None', 'anspress-question-answer' ); ?></option>
				<option value="count" <?php echo selected($orderby, 'count' ); ?>><?php _e('Count', 'anspress-question-answer' ); ?></option>
				<option value="id" <?php echo selected($orderby, 'id' ); ?>><?php _e('ID', 'anspress-question-answer' ); ?></option>
				<option value="name" <?php echo selected($orderby, 'name' ); ?>><?php _e('Name', 'anspress-question-answer' ); ?></option>
				<option value="slug" <?php echo selected($orderby, 'slug' ); ?>><?php _e('Slug', 'anspress-question-answer' ); ?></option>
				<option value="term_group" <?php echo selected($orderby, 'term_group' ); ?>><?php _e('Term group', 'anspress-question-answer' ); ?></option>
            </select>
		</p>
		<p>
			<label for="<?php echo $this->get_field_id( 'order' ); ?>"><?php _e( 'Order:', 'anspress-question-answer' ); ?></label>
			<select class="widefat" id="<?php echo $this->get_field_id( 'order' ); ?>" name="<?php echo $this->get_field_name( 'order' ); ?>">
				<option value="DESC" <?php echo selected($order, 'DESC' ); ?>><?php _e('DESC', 'anspress-question-answer' ); ?></option>
				<option value="ASC" <?php echo selected($order, 'ASC' ); ?>><?php _e('ASC', 'anspress-question-answer' ); ?></option>
            </select>
		</p>
		<p>
			<label for="<?php echo $this->get_field_id( 'icon_width' ); ?>"><?php _e( 'Icon width:', 'anspress-question-answer' ); ?></label>
			<input class="widefat" id="<?php echo $this->get_field_id( 'icon_width' ); ?>" name="<?php echo $this->get_field_name( 'icon_width' ); ?>"
			  type="text" value="<?php echo esc_attr( $icon_width ); ?>">
		</p>
		<p>
			<label for="<?php echo $this->get_field_id( 'icon_height' ); ?>"><?php _e( 'Icon height:', 'anspress-question-answer' ); ?></label>
			<input class="widefat" id="<?php echo $this->get_field_id( 'icon_height' ); ?>" name="<?php echo $this->get_field_name( 'icon_height' ); ?>"
			  type="text" value="<?php echo esc_attr( $icon_height ); ?>">
		</p>
		<?php
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment