質問編集履歴
1
解決した際のコードを追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -65,3 +65,133 @@
|
|
65
65
|
また、プラグインmixitupのサイトはこちらです。
|
66
66
|
|
67
67
|
[https://www.kunkalabs.com/mixitup/](https://www.kunkalabs.com/mixitup/)
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
---
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
### 【最終追記】
|
76
|
+
|
77
|
+
どなたかのお役に立つことがあるかもしれないので、修正後のコードを記載しておきます。
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
```PHP
|
82
|
+
|
83
|
+
<nav class="box">
|
84
|
+
|
85
|
+
<?php
|
86
|
+
|
87
|
+
$args = array(
|
88
|
+
|
89
|
+
'menu' => 'global-navigation',
|
90
|
+
|
91
|
+
'menu_class' => 'globalnavi',
|
92
|
+
|
93
|
+
'container' => false,
|
94
|
+
|
95
|
+
'walker' => new edit_Walker_Nav_Menu()
|
96
|
+
|
97
|
+
);
|
98
|
+
|
99
|
+
wp_nav_menu($args);
|
100
|
+
|
101
|
+
?>
|
102
|
+
|
103
|
+
</nav>
|
104
|
+
|
105
|
+
```
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
```PHP
|
110
|
+
|
111
|
+
class edit_Walker_Nav_Menu extends Walker_Nav_Menu {
|
112
|
+
|
113
|
+
function start_el( &$output, $item, $depth, $args ) {
|
114
|
+
|
115
|
+
// メニュー内の各項目に対する処理
|
116
|
+
|
117
|
+
if (in_array('menu-item-type-custom', $item->classes)) {
|
118
|
+
|
119
|
+
// カスタムリンクが対象
|
120
|
+
|
121
|
+
$output .= $this->create_b_tag($item, $depth, $args);
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
else {
|
126
|
+
|
127
|
+
// カスタムリンク以外
|
128
|
+
|
129
|
+
$output .= $this->create_a_tag($item, $depth, $args);
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
private function create_a_tag($item, $depth, $args) {
|
136
|
+
|
137
|
+
// link attributes
|
138
|
+
|
139
|
+
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
|
140
|
+
|
141
|
+
$item_output = sprintf( '<li>%1$s<a%2$s>%3$s%4$s%5$s</a>%6$s',
|
142
|
+
|
143
|
+
$args->before,
|
144
|
+
|
145
|
+
$attributes,
|
146
|
+
|
147
|
+
$args->link_before,
|
148
|
+
|
149
|
+
apply_filters( 'the_title', $item->title, $item->ID ),
|
150
|
+
|
151
|
+
$args->link_after,
|
152
|
+
|
153
|
+
$args->after
|
154
|
+
|
155
|
+
);
|
156
|
+
|
157
|
+
return apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
private function create_b_tag($item, $depth, $args) {
|
164
|
+
|
165
|
+
// link attributes
|
166
|
+
|
167
|
+
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
|
168
|
+
|
169
|
+
// data-filterにtitle属性を利用
|
170
|
+
|
171
|
+
$title = $item->attr_title ;
|
172
|
+
|
173
|
+
$item_output = sprintf( '<li data-filter="%7$s">%1$s<a%2$s>%3$s%4$s%5$s</a>%6$s',
|
174
|
+
|
175
|
+
$args->before,
|
176
|
+
|
177
|
+
$attributes,
|
178
|
+
|
179
|
+
$args->link_before,
|
180
|
+
|
181
|
+
apply_filters( 'the_title', $item->title, $item->ID ),
|
182
|
+
|
183
|
+
$args->link_after,
|
184
|
+
|
185
|
+
$args->after,
|
186
|
+
|
187
|
+
$title
|
188
|
+
|
189
|
+
);
|
190
|
+
|
191
|
+
return apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
```
|