Skip to content

Latest commit

 

History

History
41 lines (35 loc) · 1.07 KB

File metadata and controls

41 lines (35 loc) · 1.07 KB

Builder

The order form field allows users to reorder the listed options. The most common usage of this field is using the order field to control the output of widget contents.

Example

$form_options = array(
	'ordering' => array(
		'type' => 'order',
		'label' => __( 'Element Order', 'widget-form-fields-text-domain' ),
		'options' => array(
			'section' => __( 'Section', 'widget-form-fields-text-domain' ),
			'divider' => __( 'Content', 'widget-form-fields-text-domain' ),
			'other section' => __( 'Other Section', 'widget-form-fields-text-domain' ),
		),
		'default' => array( 'section', 'divider', 'other section' ),
	),
);

Rendering the field

You can use foreach and switch to run through the through the $instance['ordering'] array. An example of this is:

foreach( $instance['ordering'] as $item ) {
	switch( $item ) {
		case 'section' :
			// output here
			break;

		case 'divider' :
			// divider here
			echo '<hr>';
			break;

		case 'other section' :
			// output other section
			break;
	}
}