Nie jestem pewien, czy to odpowiedź, ale raczej kwestia dyskusji.
Czy ktoś kiedykolwiek rozważał zaawansowane niestandardowe pola do tworzenia menu WP? Zrobiłem to kilka razy i pozwala mi to zbudować niestandardową strukturę wraz z niestandardowymi atrybutami pozycji menu i rozwinąć HTML dla menu bez skomplikowanego walkera, który byłby potrzebny z domyślnymi menu WP.
ACF
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array (
'key' => 'group_56532ec144a4b',
'title' => 'Menu',
'fields' => array (
array (
'key' => 'field_5653338918f43',
'label' => 'Menus',
'name' => 'menus',
'type' => 'flexible_content',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'button_label' => 'Add Menu',
'min' => '',
'max' => '',
'layouts' => array (
array (
'key' => '56533396b10bc',
'name' => 'menu',
'label' => 'Menu',
'display' => 'block',
'sub_fields' => array (
array (
'key' => 'field_56533fc6f25e7',
'label' => 'Menu Name',
'name' => 'menu__name',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
'readonly' => 0,
'disabled' => 0,
),
array (
'key' => 'field_56532ec718f40',
'label' => 'Menu Items',
'name' => 'menu__items',
'type' => 'flexible_content',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'button_label' => 'Add Menu Item',
'min' => '',
'max' => '',
'layouts' => array (
array (
'key' => '56532eee6ef81',
'name' => 'menuItem',
'label' => 'Menu Item',
'display' => 'block',
'sub_fields' => array (
array (
'key' => 'field_56532f0418f41',
'label' => 'Label',
'name' => 'menuITem__label',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => 50,
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
'readonly' => 0,
'disabled' => 0,
),
array (
'key' => 'field_565333d218f45',
'label' => 'Class',
'name' => 'menuItem__class',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => 50,
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
'readonly' => 0,
'disabled' => 0,
),
array (
'key' => 'field_565342ef11b29',
'label' => 'Link Type',
'name' => 'menuItem__type',
'type' => 'radio',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => 25,
'class' => '',
'id' => '',
),
'choices' => array (
'page' => 'Page',
'cat' => 'Category',
'url' => 'URL',
'cust' => 'Custom',
),
'other_choice' => 0,
'save_other_choice' => 0,
'default_value' => '',
'layout' => 'vertical',
),
array (
'key' => 'field_56532f2d18f42',
'label' => 'Page',
'name' => 'menuItem__page',
'type' => 'page_link',
'instructions' => '',
'required' => 0,
'conditional_logic' => array (
array (
array (
'field' => 'field_565342ef11b29',
'operator' => '==',
'value' => 'page',
),
),
),
'wrapper' => array (
'width' => 75,
'class' => '',
'id' => '',
),
'post_type' => array (
),
'taxonomy' => array (
),
'allow_null' => 0,
'multiple' => 0,
),
array (
'key' => 'field_5653434f11b2a',
'label' => 'Category',
'name' => 'menuItem__cat',
'type' => 'taxonomy',
'instructions' => '',
'required' => 0,
'conditional_logic' => array (
array (
array (
'field' => 'field_565342ef11b29',
'operator' => '==',
'value' => 'cat',
),
),
),
'wrapper' => array (
'width' => 75,
'class' => '',
'id' => '',
),
'taxonomy' => 'category',
'field_type' => 'select',
'allow_null' => 0,
'add_term' => 1,
'save_terms' => 0,
'load_terms' => 0,
'return_format' => 'id',
'multiple' => 0,
),
array (
'key' => 'field_5653439311b2c',
'label' => 'Custom',
'name' => 'menuItem__cstm',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => array (
array (
array (
'field' => 'field_565342ef11b29',
'operator' => '==',
'value' => 'cust',
),
),
),
'wrapper' => array (
'width' => 75,
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
'readonly' => 0,
'disabled' => 0,
),
array (
'key' => 'field_5653437011b2b',
'label' => 'URL',
'name' => 'menuItem__url',
'type' => 'url',
'instructions' => '',
'required' => 0,
'conditional_logic' => array (
array (
array (
'field' => 'field_565342ef11b29',
'operator' => '==',
'value' => 'url',
),
),
),
'wrapper' => array (
'width' => 75,
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
),
),
'min' => '',
'max' => '',
),
),
),
),
'min' => '',
'max' => '',
),
),
),
),
'location' => array (
array (
array (
'param' => 'options_page',
'operator' => '==',
'value' => 'acf-options-theme-options',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => 1,
'description' => '',
));
endif;
UX
function acfMenu($name) {
if( function_exists('get_field') ) :
$getMenus = get_field('menus', 'option');
foreach($getMenus as $menuData) :
if( $menuData['menu__name'] == $name ) :
// Do stuff to build your menu
endif;
endforeach;
endif;
}
To tylko krótka próbka, ale dzięki opcjom, które oferuje ACF, możesz przypiąć wszelkiego rodzaju rzeczy do elementu menu, a następnie dowolnie kodować interfejs użytkownika.
W zależności od konkretnego pytania można z kolei zastosować selekcję warunkową do rodzaju dostarczanego linku (patrz załączony obraz). ACF pozwala na wiele różnych parametrów, takich jak linki do stron, linki kategorii lub proste adresy URL. Warunkowy wybór tych elementów pozwoliłby zmienić typ pozycji menu bez usuwania klas lub innych atrybutów.