Reputation: 78
So I am practicing PHP and making one wordpress theme, and I have some links in the footer which are 3 sepearte navigation menus. I have them created in the Dashboard, registered in the functions.php file and called in the footer.php file and everything works great.
This is how I called the menus in the footer.php So I repeated this code 3 times, for each menu. (Footer, Footer1 and Footer2)
<?php
wp_nav_menu(array(
'menu' => 'Footer',
'theme_location' => 'footer',
'container' => 'nav',
'container_class' => 'footer-links-content',
'menu_class' => 'footer_list'
));
?>
So, is there any better way I can call this 3 menus, with lesss code? Maybe some foreach loop?
Thanks!
Upvotes: 0
Views: 746
Reputation: 2168
Make an array of the footer values you want, then use foreach
and substitute the name with the iterator variable..
<?php
$footerList = array("Footer", "Footer1", "Footer2");
foreach ($footerList as $idx=>$footer) {
wp_nav_menu(array(
'menu' => $footer,
'theme_location' => 'footer',
'container' => 'nav',
'container_class' => 'footer-links-content',
'menu_class' => 'footer_list'
));
}
?>
Upvotes: 1