これが答えかどうかはわかりませんが、議論のポイントです。
WPメニューを作成するために高度なカスタムフィールドを検討したことがある人はいますか?これを数回行いました。これにより、カスタムメニュー項目属性とともにカスタム構造を構築し、デフォルトのWPメニューで必要な複雑なウォーカーなしでメニューのHTMLを構築できます。
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;
}
これは簡単なサンプルですが、ACFが提供するオプションを使用して、あらゆる種類のものをメニュー項目に追加し、UIを自由にコーディングできます。
特定の質問に適用する場合、条件付きの選択を、提供するリンクのタイプに適用できます(添付画像を参照)。ACFでは、ページリンク、カテゴリリンク、ストレートURLなど、さまざまなパラメーターを使用できます。これらの項目を条件付きで選択すると、クラスやその他の属性を消去せずにメニュー項目のタイプを変更できます。