Q: Import Uikit in yii\bootstrap\NavBar - css

I use Yii2 framework and I'm writing a navbar in layout/main.php. I have to use Uikit so I imported css and js files in my project, now the problem is that yii\bootstrap\NavBar seems not to be customizable and doesn't support uikit classes. Is there a way to use uk classes and span tag with yii navbar?
I have this HTML code:
<nav class="uk-navbar-container" uk-navbar>
<div class="uk-navbar-left">
<ul class="uk-navbar-nav">
<li class="uk-active">Active</li>
<li>
Parent
<div class="uk-navbar-dropdown">
<ul class="uk-nav uk-navbar-dropdown-nav">
<li class="uk-active">Active</li>
<li><a href="#">Item
<span class="uk-icon uk-margin-small-right" uk-icon="icon: star"></span>
</a></li>
<li class="uk-nav-header">Header</li>
<li>Item</li>
<li>Item</li>
<li class="uk-nav-divider"></li>
<li>Item</li>
</ul>
</div>
</li>
<li>Item</li>
</ul>
</div>
<div class="uk-navbar-right">
<ul class="uk-navbar-nav">
<li>
Parent
<div class="uk-navbar-dropdown">
<ul class="uk-nav uk-navbar-dropdown-nav">
<li class="uk-active">Active</li>
<li>Item</li>
<li class="uk-nav-header">Header</li>
<li>Item</li>
<li>Item</li>
<li class="uk-nav-divider"></li>
<li>Item</li>
</ul>
</div>
</li>
</ul>
</div>
and this is the implementation with yii2 component:
NavBar::begin([
'brandLabel' => Html::img('/img/my_image.png'),
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'uk-navbar navbar-fixed-top uk-align-center',
'style' => 'background-color: orange; color: black ; height: 100px;
margin-top: 0; margin-bottom: 0',
]
]);
$menuItems = [
['label' => 'Home', 'url' => Yii::$app->homeUrl],
['label' => 'Item', 'url' => ['/item']],
['label' => 'Item', 'url' => ['/item']],
['label' => 'Item', 'url' => ['/item']],
['label' => 'Item', 'url' => ['/item']],
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right uk-link-reset',
'style' => 'color: white'
],
'items' => $menuItems,
]);
NavBar::end();

You need to include html options inside each individual item
$menuItems = [
['label' => 'Home', 'url' => Yii::$app->homeUrl],
[
'label' => 'Item <span class="uk-icon uk-margin-small-right" uk-icon="icon: star"></span>',
'encode' => false,
'url' => ['/item'],
'options' => ['class' => 'uk-active'],
],
['label' => 'Item', 'url' => ['/item']],
['label' => 'Item', 'url' => ['/item']],
['label' => 'Item', 'url' => ['/item']]
];
More details from the item documentation:
label: string, required, the nav item label.
url: optional, the item's URL. Defaults to "#".
visible: boolean, optional, whether this menu item is visible. Defaults to true.
linkOptions: array, optional, the HTML attributes of the item's link.
options: array, optional, the HTML attributes of the item container (LI).
active: boolean, optional, whether the item should be on active state or not.
dropDownOptions: array, optional, the HTML options that will passed to the yii\bootstrap\Dropdown widget.
items: array|string, optional, the configuration array for creating a yii\bootstrap\Dropdown widget, or a string representing the dropdown menu. Note that Bootstrap does not support sub-dropdown menus.
encode: boolean, optional, whether the label will be HTML-encoded. If set, supersedes the $encodeLabels option for only this item.

Related

wrapping parent and child pages in separate ul in wp nav menu

I need the nav menu structure like the following.
<ul class="side-menu-list">
<li>Parent Page 1
<ul>
<li>Traditional Braces</li>
<li>Lingual Braces</li>
<li>Invisalign</li>
<li>Temporary Anchorage Devices</li>
<li>Surgical Orthodontics</li>
<li>TMJ Treatment</li>
<li>All About Retainers</li>
<li>Emergency Treatment</li>
</ul>
</li>
</ul>
<ul class="side-menu-list">
<li>Paent Page 2
<ul>
<li>Early Treatment/Prevention</li>
<li>Two-Phase Treatment</li>
<li>Hometown Smiles Gallery</li>
</ul>
</li>
</ul>
Which means every parent page and its sub pages should be wrapped in a ul. So iam looking for a custom walker menu so that every main menu and its sub menus will be wrapped in a ul tag dynamically.
// Register two menus
// Go to Menus and add menu items to each menu
// call the wp_nav_menu function twice.
// this goes in functions.php
register_nav_menus( array(
'primary' => __( 'Primary', 'text-domain' ),
'secondary' => __( 'Secondary', 'text-domain' )
) );
<ul class="side-menu-list">
<li>Parent Page 1
// display the menu on front end
wp_nav_menu(
array(
'theme_location' => 'primary',
'depth' => 2,
'container' => 'div',
'container_id' => 'primary',
'container_class' => 'primary',
'menu_class' => 'ul-class' ) );
</li>
</ul>
<ul class="side-menu-list">
<li>Parent Page 1
wp_nav_menu(
array(
'theme_location' => 'secondary',
'depth' => 2,
'container' => 'div',
'container_id' => 'secondary',
'container_class' => 'secondary',
'menu_class' => 'ul-class' ) );
</li>
</ul>

Create fixed navbar adn fixed scrolled sidebar in adminLTE integration with yii2

I use yii with adminLTE from this git, dmstr.
So, I copied the layout from example-view's folder to my view/layout
My question is
How to make the navbar is fixed
The sidebar is fixed , but can scrolled ?
This is my code :
navbar
<?php
use yii\helpers\Html;
/* #var $this \yii\web\View */
/* #var $content string */
?>
<header class="main-header">
<?= Html::a('<span class="logo-mini">TMS</span><span class="logo-lg">' . Yii::$app->name . '</span>', Yii::$app->homeUrl, ['class' => 'logo']) ?>
<nav class="navbar navbar-static-top" role="navigation">
//Some element
</nav>
</header>
sidebar
<aside class="main-sidebar">
<section class="sidebar">
<!-- Sidebar user panel -->
<div class="user-panel">
<div class="pull-left image">
<img src="<?= $directoryAsset ?>/img/user2-160x160.jpg" class="img-circle" alt="User Image"/>
</div>
<div class="pull-left info">
<p>Dzil Jalal</p>
<i class="fa fa-circle text-success"></i> Online
</div>
</div>
<!-- search form -->
<form action="#" method="get" class="sidebar-form">
<div class="input-group">
<input type="text" name="q" class="form-control" placeholder="Search..."/>
<span class="input-group-btn">
<button type='submit' name='search' id='search-btn' class="btn btn-flat"><i class="fa fa-search"></i>
</button>
</span>
</div>
</form>
<!-- /.search form -->
<?=
dmstr\widgets\Menu::widget(
[
'options' => ['class' => 'sidebar-menu'],
'items' => [
['label' => 'Menu Yii2', 'options' => ['class' => 'header']],
['label' => 'Gii', 'icon' => 'fa fa-file-code-o', 'url' => ['/gii']],
['label' => 'Debug', 'icon' => 'fa fa-dashboard', 'url' => ['/debug']],
['label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest],
[
'label' => 'Same tools',
'icon' => 'fa fa-share',
'url' => '#',
'items' => [
['label' => 'Gii', 'icon' => 'fa fa-file-code-o', 'url' => ['/gii'],],
['label' => 'Debug', 'icon' => 'fa fa-dashboard', 'url' => ['/debug'],],
[
'label' => 'Level One',
'icon' => 'fa fa-circle-o',
'url' => '#',
'items' => [
['label' => 'Level Two', 'icon' => 'fa fa-circle-o', 'url' => '#',],
[
'label' => 'Level Two',
'icon' => 'fa fa-circle-o',
'url' => '#',
'items' => [
['label' => 'Level Three', 'icon' => 'fa fa-circle-o', 'url' => '#',],
['label' => 'Level Three', 'icon' => 'fa fa-circle-o', 'url' => '#',],
],
],
],
],
],
],
],
]
)
?>
</section>
</aside>
For the help, it so appreciated
To make the navbar fixed, put
class="navbar navbar-fixed-top"
instead of
class="navbar navbar-static-top"

Register Custom menu in wordpress

How to register this menu in wordpress dynamically ?
i'am having problem to dynamic menu in wordpress
<nav id="nav">
<ul>
<li>Division
<ul class="dropotron dropotron-level-0 center" style="-moz-user-select: none; position: absolute; z-index: 1000; left: 184.767px; top: 29px; opacity: 1; display: none;">
<li ><a style="display: block;" href="real-estate.html">Real Estate</a></li>
<li><a style="display: block;" href="waterpump.html">Water Pump</a></li>
<li ><a style="display: block;" href="fmcg.html">FMCG</a></li>
<li ><a style="display: block;" href="infrastructure.html">Infrastructure Project</a></li>
</ul>
</li>
<li >About Us</li>
<li class="break">Career</li>
<li >Contact Us</li>
</ul>
</nav>
Thanks
i'm not sure i'm fully understand what you'r meant when you say 'register this menu in wordpress dynamically', but if you meant to register custom menu and display it so follow this:
put this code on the 'functions.php' file: (if you are not using a theme of your own then create a child theme if you didn't already)
function register_your_menu() {
register_nav_menu('your-menu-location',__( 'Your Menu Description' ));
}
add_action( 'init', 'register_your_menu' );
*register your new menu - it will display the new menu on the admin panel so set it as you like.
put this code on the place you want the menu to appear on the theme and customize the '$defaults' settings as you like (you can find more info here: http://codex.wordpress.org/Function_Reference/wp_nav_menu):
if ( has_nav_menu( 'your-menu-location' ) ) {
$defaults = array(
'theme_location' => 'your-menu-location',
'menu' => '',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => ''
);
wp_nav_menu( $defaults );
}

wp_nav_menu not outputting as expected from configuration

I've got a nav function in functions.php:
function html5blank_nav()
{
wp_nav_menu(
array(
'theme_location' => 'header-menu',
'menu' => '',
'container' => false,
'menu_class' => 'nav',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => ''
)
);
}
And it's called in header.php with:
<?php html5blank_nav(); ?>
And my output is:
<div class="nav">
<ul>
<li class="page_item page-item-2">Sample Page</li>
<li class="page_item page-item-4">Test page</li>
</ul>
</div>
But What I was trying to achieve was this structure:
<ul class="nav">
<li>Sample Page</li>
<li>Test page</li>
</ul>
I thought that setting container=false would get rid of the containing divs, and that setting menu_class='nav' would add the nav class to the ul as it states here: http://codex.wordpress.org/Function_Reference/wp_nav_menu
Why isn't it recognising my settings?
from the Codex:
In order to remove navigation container, theme location specified in functions.php and used among arguments in function wp_nav_menu ( eg. 'theme_location' => 'primary-menu' ) must have a menu assigned to it in administration! Otherwise argument 'container' => 'false' is ignored

how to set css and html structure in wp_nav_menu() function in wordpress

I have a HTML coded navigation menu which has CSS style and cool animation.
Now i wants to add this CSS and structure in Word Press. I have tried and also used in wp_nav_menu() .But result is so far. How could i use this CSS in Word Press.
CSS also included and working fine if i am using statically navigation HTML.
$defaults = array(
'theme_location' => 'header-menu',
'menu' => '',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => ''
);
wp_nav_menu( $defaults );
Wants to add this css in Wordpress navigation menu
<ul class="menu">
<li class="current-menu-parent">Home
<ul class="sub-menu">
<li class="current-menu-item">Background Color</li>
<li>Background Color With Fullwidth Slider</li>
<li>Clean Style</li>
<li>Clean Style With Fullwidth Slider</li>
<li>Background Image</li>
</ul>
</li>
<li>Pages
<ul class="sub-menu">
<li>About</li>
<li>Full Width</li>
<li>Gallery</li>
<li>404 Page</li>
<li>Sitemap</li>
</ul>
</li>
</ul>
Is not so dificult to do that. You need to declare the class of the menu in array.
here is an exemple:
<?php $defaults = array(
'theme_location' => '',
'menu' => 'TopMenu',
'container' => 'ul',
'container_class' => 'topmenu-{topmenu slug}-container',
'container_id' => 'topmenu',
'menu_class' => 'topmenu',
'menu_id' => 'topmenu-{topmenu slug}[-{increment}]',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => ''
); ?>
<?php wp_nav_menu( $defaults ); ?>
In this "topmenu" is the css class. I believe that from here you will be able to customize your menu.
Hope it help's you!
If you need a css sample, just let me know!

Resources