0
私は通常のWordPressメニュー(外観>メニュー)によって設定されたサイドバーメニューを持っています。WordPressのカスタムwp_nav_menu_itemsの位置を変更
また、WPメニューの下部に追加される 'wp_nav_menu_items'を使用してカスタムメニューを作成しました。私の問題は、そのカスタムメニューの順序を変更できる必要があることです。
- りんご
- バナナ
- 梨私が達成したいのですがどのよう
- オレンジ
- パイナップル(カスタムメニュー使用wp_nav_menu_items)
:これは、現在、どのように見えるかです:
- りんご
- バナナ
- パイナップル(wp_nav_menu_itemsを使用して、カスタムメニュー)
- 梨
- オレンジ
これは私のコードは、現在どのように見えるかです:
class My_Walker_Nav_Menu extends Walker_Nav_Menu {
function start_lvl(&$output, $depth = 0, $args = Array()) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<ul class=\"childnav\">\n";
}
function end_lvl(&$output, $depth = 0, $args = Array()) {
$indent = str_repeat("\t", $depth);
$output .= "$indent</ul>\n";
}
}
add_filter('wp_nav_menu_items', 'custom_pineapple_navigation', 10, 2);
function custom_buy_navigation ($items, $args) {
$your_query = new WP_Query('pagename=pineapples');
while ($your_query->have_posts()) : $your_query->the_post();
$items .= '<li class="haschild"><a href="#">Pineapple</a>
<ul class="childnav">
<li class="breadcrumb"><a href="#">Back to main menu</a></li>
<li class="label"><a href="#">Pineapple</a></li><span class="scrollMenu scrollbar-outer">';
$customPosts = get_field('my_pineapple_custom_field');
if($customPosts):
foreach($customPosts as $customPost):
setup_postdata($customPost);
$items .= '<li><a href="'.get_permalink($customPost->ID).'">'.get_the_title($customPost->ID).'</a></li>';
endforeach;
wp_reset_postdata();
endif;
$items .= '</span></ul></li>';
endwhile;
wp_reset_postdata();
// More Queries like above
return $items;
}
はする方法はあります私は後に何を達成するのですか?
ようなステートメントは、あなたのメニューがwp_queryを持っていない場合は、あなたを変更する必要がありますか?そうであればソートを単に「タイトル」に変更できます。アルファベット順にソートされます。 – Dorvalla
残念ながら、私はアルファベット順に注文しようとしていません。ちょうど例のように見えました。しかし、それは良いアイデアでした! – user1788364