How can I add in current menu fontawesome <i> - php

I am trying to indicate the active menu using an icon in PHP.
Here my html version :
<ul class="languages">
<li class="active">
English <i class="fa fa-check"></i>
</li>
<li>Spanish</li>
</ul>
Here my PHP version
<li class="languagesSelector">
<i class="fa fa-globe"></i>
<a><?php echo __("Languages") ?></a>
<ul class="languages">
<?php
$currentLanguage = $user->language; // remember language
foreach($languages as $language) {
if(!$page->viewable($language)) continue; // is page viewable in this language?
$user->language = $language;
if($language->id == $currentLanguage->id) {
echo "<li class='active'>" <i class='fa fa-check'></i> ;
} else {
echo "<li>";
}
echo "<a href='$page->url'>$language->title</a></li>";
}
$user->language = $currentLanguage; // restore language
?>
</ul>
</li>
How can I achieve do this using just a function in PHP?

Related

Show active navigation for current page

i'm having some problems with my html, php code. With this code, my nav will show the active li but the other pages which are not active won't have style or links.
<!--/. PHP "active" -->
<?php
$current_url = basename($_SERVER['PHP_SELF']);
$active = "class=\"active-menu\"";
?>
<!--/. PHP "active" -->
<nav class="navbar-default navbar-side" role="navigation">
<div class="sidebar-collapse">
<ul class="nav" id="main-menu">
<li>
<?php if ($current_url == "home.php") { ?>
<a <?php echo $active;?> href="home.php"><?php } ?><i class="fa fa-dashboard"></i> Dashboard</a>
</li>
<li>
<?php if ($current_url == "new.php") { ?>
<a <?php echo $active;?> href="new.php"><?php } ?><i class="fa fa-qrcode"></i> Nieuw item toevoegen</a>
</li>
<li>
<?php if ($current_url == "show.php") { ?>
<a <?php echo $active;?> href="show.php"><?php } ?><i class="fa fa-qrcode"></i> Bekijk inventaris</a>
</li>
<li>
<?php if ($current_url == "profile.php") { ?>
<a <?php echo $active;?> href="profile.php"><?php } ?><i class="fa fa-user"></i> Gebruikersprofiel</a>
</li>
<li>
<i class="fa fa-sitemap"></i> Gebruikers<span class="fa arrow"></span>
<ul class="nav nav-second-level">
<li>
Beheerders
</li>
<li>
ICT - Verantwoordelijken
</li>
<li>
Raadplegers
</li>
</ul>
</li>
<li>
<?php if ($current_url == "empty.php") { ?>
<a <?php echo $active;?> href="empty.php"><?php } ?><i class="fa fa-fw fa-file"></i> Lege pagina</a>
</li>
</ul>
</div>
</nav>
the pages with no styling will also not have a link. The active-menu class has the styling.
Your if condition it is wrong.
Try something like this in every <li>.
<li>
<a <?php echo $current_url == "home.php" ? $active : ''; ?> href="home.php"><i class="fa fa-dashboard"></i> Dashboard</a>
</li>
<li>
<a href="new.php" <?php if ($current_url == "new.php") {echo $active;}?>>
<i class="fa fa-qrcode"></i> Nieuw item toevoegen
</a>
</li>
Put your list like this
You should make another class, like $not_active = "class=\"not-active-menu\"";
And add that to your code
<li>
<a href="something.php" <?php if ($current_url == "something.php") {echo $active;} else { echo $not_active; }?>>
<i class="fa fa-qrcode"></i> something
</a>
</li>

how to view submenu on click using php,html

I'm trying to view submenu after click on parent.
Classes->Primary School->(Grade1,Grade2,Grade3,Grade4,Grade5,Grade6)
Classes->Middle School->(Grade7,Grade8,Grade9)
Classes->Secondary School->(Grade10,Grade11,Grade12)
<div class="collapse navbar-collapse" id="main-navigation">
<ul class="nav navbar-nav navbar-right">
<?php foreach ($data as $menu) { ?>
<?php if(!$menu->children) { ?>
<li><?php echo $menu->name; ?></li>
<?php }
else {
?>
<li class="dropdown open">
<a href="#" class="dropdown-toggle " data-toggle="dropdown">
<?php echo $menu->name; ?>
<span class="fa fa-angle-down"></span>
</a>
<ul class="dropdown-menu open" role="menu">
<?php
foreach ($menu->children as $child) {
?>
<li><?php echo $child->name; ?></li>
<?php
foreach ($child->children as $sub_child) {
?>
<li class="dropdown-submenu">
<?php echo $sub_child->name; ?><span class="fa fa-angle-down"></span>
<ul class="dropdown-submenu" role="menu">
<?php } ?>
<?php } ?>
</ul>
</li>
<?php } ?>
<?php } ?>
</ul>
</li>
</ul>
</div>
The result:
Problem with result
I want to view Grade 1 to Grade 6 after click on Primary school and from Grade 7 to Grade 9 after click on Middle school ...
Please help!
You have an open <ul class="dropdown-submenu" role="menu"> tag without any <li> or <a>'s being generated inside of it. Then you close two each statements before closing the <ul> tag.
<?php foreach ($child->children as $sub_child) { ?>
<li class="dropdown-submenu">
<a href="#" style="color:black;" class="dropdown-toggle " data-toggle="dropdown">
<?php echo $sub_child->name; ?><span class="fa fa-angle-down"></span>
</a>
<ul class="dropdown-submenu" role="menu">
<?php } ?>
<?php } ?>
</ul>
</li>
This will be causing all sorts of unintended markup output. Fix that and it should fix your problem. If not, you'll atleast be a lot closer.

CodeIgniter: Dropdown Within a Dropdown

Image of the navigation bar
The "User" should be a dropdown. The sub-menu are the ones below it
This is the code I have. How do you make the second condition a DROPWDOWN WITHIN A DROPDOWN? (the elseif part)
<ul class="nav navbar-nav">
<?php
foreach ($nav as $item) {
if (empty($item['children'])) {
?>
<li<?php if (!empty($item['is_active'])) { ?> class="active"<?php } ?>>
<a href="<?php echo $item['link']; ?>"><?php if ($item['icon'] != '') { ?>
<i class="<?php echo $item['icon']; ?>" data-toggle="tooltip" data-placement="bottom" data-original-title="A large tooltip."></i> <?php } echo $item['label']; ?></a></li>
<?php
}
elseif (!empty($item['children']) && empty($item['children/'])) {
?>
<li class="dropdown <?php if (empty($item['children'])) { ?> active<?php } ?>">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown">
<?php if ($item['icon'] != '') { ?>
<i class="<?php echo $item['icon']; ?>"></i>
<?php echo $item['label']; ?>
<b class="caret"></b><?php } ?>
</a>
<ul class="dropdown-menu scrollable-menu" role="menu">
<?php
_main_menu_widget_display_children($item['children']);
?>
</ul>
</li>
<?php
}
else
{
?>
<li class="dropdown <?php if (!empty($item['is_active'])) { ?> active<?php } ?>">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown">
<?php if ($item['icon'] != '') { ?>
<i class="<?php echo $item['icon']; ?>"></i>
<?php echo $item['label']; ?>
<b class="caret"></b><?php } ?>
</a>
<ul class="dropdown-menu scrollable-menu" role="menu">
<?php
_main_menu_widget_display_children($item['children']);
?>
</ul>
</li>
<?php
}
}
?>
</ul>

Hide Side nav on login page PHP

I have the following side nav in side-nav.php
<?php
if (isset($_SESSION['account'])) {
$current_user = get_user_on_uin($_SESSION['account']['ein']);
$current_user = $current_user->fetch_assoc();
}
//show sidebar on everypage except login & graph
$page_name = basename(__FILE__);
//var_dump($page_name);
//die();
if ($page_name != 'login.php' || $page_name != 'graph.php'){
echo '<div class="navbar-default navbar-static-side" role="navigation">
<div class="sidebar-collapse">
<ul class="nav" id="side-menu">
<li>
<li>
<i class="fa fa-file-text"></i> Request a Coach
</li>
<li>
<i class="fa fa-database"></i> View All Requests
</li>';
if (isset($current_user) && $current_user['user_role']!='reactive_coach' || $current_user['user_role']!='proactive_coach'){
echo '<li>
<i class="fa fa-user fa-fw"></i> View Accepted Requests
</li>
<li><i class="fa fa-exclamation-triangle"></i> View Rejected Requests
</li>
<li><i class="fa fa-binoculars"></i> View Coach Assigned Requests
</li>';
}
echo '<li><i class="fa fa-user fa-fw"></i> View Completed Requests
</li>
<li class="divider"></li>';
if (isset($current_user) && $current_user['user_role']=='reactive_coaching_manager' || $current_user['user_role']=='proactive_coaching_manager' || $current_user['user_role']=='OEM' || $current_user['user_role']=='GM'){
echo '<li><i class="fa fa-area-chart"></i> Analytics
</li>';
}
echo '<li><i class="fa fa-sign-out fa-fw"></i> Logout
</li>';
echo '</ul>
</div>
</div>';
}
?>
I do not wish to show this side-nav.php to appear on login.php or graph.php pages but it still does...
I tried by successfully getting the current page by:
$page_name = basename(__FILE__);
But the if ($page_name != 'login.php' || $page_name != 'graph.php') seems to be true all the time...
is there a different way of doing this?
Thanks
You're using the wrong operator, it is contradicting itself.
You need to use the && operator instead of ||
if ($page_name != 'login.php' && $page_name != 'graph.php')

Add HTML Class after 3 elements in PHP

My HTML should seen like this;
<div class="row">
<div class="col-xs-6">
<ul class="list-unstyled">
<li><i class="fa fa-check-circle"></i> Car</li>
<li><i class="fa fa-check-circle"></i> Google</li>
<li><i class="fa fa-check-circle"></i> Building</li>
</ul>
</div>
<div class="col-xs-6">
<ul class="list-unstyled">
<li><i class="fa fa-check-circle"></i> Bathroom</li>
<li><i class="fa fa-check-circle"></i> Facebook</li>
<li><i class="fa fa-check-circle"></i> Twitter</li>
</ul>
</div>
</div>
In database, all data is in same field with there is a comma between them(e.g. Car,Google,Building,Bathroom, Facebook, Twitter).
So, I'm using this code to seperate them;
<?php echo str_replace(',', '</li><li><i class="fa fa-check-circle"></i>', $data); ?>
I need to get the same result with HTML, how can I do this?
Thanks in advance.
$arrData = explode(",", $data); // comma separated list of words
$i = 0; // temp counter
echo '<div class="row">';
foreach ($arrData as $word)
{
if ($i==0) { echo '<div class="col-xs-6"><ul class="list-unstyled">'; } // open first html containers
echo '<li><i class="fa fa-check-circle"></i>'.$word.'</li>'; // create li
$i++; // increase counter
if ($i==2) // this is the 3rd element in loop
{
echo '</ul></div>'; // close html containers
$i=0; // reset counter, so proccess repeats
}
}
echo '</div>';
This code will do what you need, as long as you always have 6 words in your array (or 9, 12, 15, etc).
<?php
$v1=explode(",",$data);
$data0=$v1[0];
$data1=$v1[1];
$data2=$v1[2];
$data3=$v1[3];
$data4=$v1[4];
$data5=$v1[5];
?>
<div class="row">
<div class="col-xs-6">
<ul class="list-unstyled">
<li><i class="fa fa-check-circle"></i> <?php echo $data0; ?></li>
<li><i class="fa fa-check-circle"></i> <?php echo $data1; ?></li>
<li><i class="fa fa-check-circle"></i> <?php echo $data2; ?></li>
</ul>
</div>
<div class="col-xs-6">
<ul class="list-unstyled">
<li><i class="fa fa-check-circle"></i> <?php echo $data3; ?></li>
<li><i class="fa fa-check-circle"></i> <?php echo $data4; ?></li>
<li><i class="fa fa-check-circle"></i> <?php echo $data5; ?></li>
</ul>
</div>
</div>
You need to explode and loop through it... look at this and it should help you understand
$pieces = explode(",", $data);
foreach($pieces as $value){
echo '<li><i class="fa fa-check-circle"></i>'.$value.'</li>';
}

Categories