Using Piklist you can easily display your Menus as Radio, Checkboxes or a Select list (dropdowns). Easily include them in custom theme settings, or when creating posts. This simple tutorial will show you how.
We’re are going to use the WordPress function wp_get_nav_menus()
, to get our menus. This function stores data in an array, and with Piklist, parsing an array and displaying it as a list is really easy. This array stores all menus in an Object, and then breaks them out. You have access to fields like term_id, name, slug, etc. We are going to assign each item in the dropdown to the slug, but show the name:
piklist('field', array(
'type' => 'select'
,'field' => 'sidebar_left'
,'label' => 'Choose Sidebar Menu'
,'value' => 'none'
,'choices' => array(
'' => 'Choose Menu'
)
+ piklist(wp_get_nav_menus()
,array(
'slug'
,'name'
)
)
));
Let’s take a look at this code:
Checkbox:
To make this a Checkbox, just change 'type' => 'select'
, to 'type' => 'checkbox'
.
Radio Buttons:
To make this Radio Buttons, just change 'type' => 'select'
, to 'type' => 'radio'
.
Yes, it’s that easy!
This documentation is a community effort. Please create an issue or pull request to help!