Last active
January 13, 2017 21:30
-
-
Save smutek/8daf4ad06b4051f5278c793cd9dc9646 to your computer and use it in GitHub Desktop.
Bootstrap 4 navigation accounting for Blade in Sage 9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
// Add to functions, or to a dedicated controllers file | |
// Needs a global body class to hook into | |
/** | |
* Navigation arguments | |
* | |
* @param $data | |
* | |
* @return mixed | |
*/ | |
function navControl( $data ) { | |
// Pass the walker class to a var, so it | |
// doesn't instantiate here. | |
$bootstrapWalker = 'wp_bootstrap_navwalker'; | |
// Main Nav | |
$mainNavArgs = [ | |
'theme_location' => 'primary_navigation', | |
'walker' => new $bootstrapWalker, | |
'menu_class' => 'navbar-nav mr-auto' | |
]; | |
$data['mainNavArgs'] = $mainNavArgs; | |
return $data; | |
} | |
add_filter( 'sage/template/global/data', 'App\\navControl' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<nav class="navbar navbar-toggleable-md navbar-light bg-faded"> | |
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" | |
data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" | |
aria-label="Toggle navigation"> | |
<span class="navbar-toggler-icon"></span> | |
</button> | |
<a class="navbar-brand" href="{{ home_url('/') }}">{{ get_bloginfo('name', 'display') }}</a> | |
<div class="collapse navbar-collapse" id="navbarSupportedContent"> | |
@if (has_nav_menu('primary_navigation')) | |
{!! wp_nav_menu($mainNavArgs) !!} | |
@endif | |
</div> | |
</nav> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// In helpers.php, or whereveer makes the most sense to you | |
/* | |
* Add global body class to hook our data up to | |
*/ | |
add_filter( 'body_class', function( $classes ) { | |
return array_merge( $classes, array( 'global' ) ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment