How to add Last Page Link to the Pagination bootstrap, im searching in the internet but no one success.
my code for pagi
<nav aria-label="Page navigation example">
<ul class="pagination">
<li class="page-item">
<a class="page-link" href="archives.php" aria-label="Previous">
<span aria-hidden="true">«</span>
<span class="sr-only">Previous</span>
</a>
</li>
<?php for ($page=1; $page <= $total_pages ; $page++):?>
<li class="page-item active">
</li>
<li class="page-item">
<?php echo $page; ?>
</li>
<?php endfor; ?>
<li class="page-item">
<a class="page-link" href="#" aria-label="Next">
<span aria-hidden="true">»</span>
<span class="sr-only">Next</span>
</a>
</li>
</ul>
</nav>
for the first page im just need to add /archives.php
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.
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>
The nav prior to sign in or register has the following links:
Home,
Blog,
Write a Blog,
Sign in,
Register,
When a normal user signs in the nav links will change to:
Hello (name of user),
Home,
Blog,
Write a blog,
Logout,
When the admin logs in the nav displays the following:
Hello (name of user),
Home,
Blog,
Write a blog,
Admin,
Logout,
My issue is I would like to remove the link 'write a blog' when the admin signs in. Any advice on how I can adapt my code to do this would be great. Below is the HTML & Php code in the header.php:
<header>
<div class="wrap-header zerogrid">
<div id="logo"><img src="/assets/images/logo_blog.png"/></div>
<nav>
<div class="wrap-nav">
<div class="menu">
<ul class="list-unstyled">
<? if ($_SESSION['user']['first_name']): ?>
<li><i class="icon fa fa-user"></i> Hello <?= $_SESSION['user']['first_name'] ?></li>
<? endif ?>
<li><i class="icon fa fa-home"></i> Home</li>
<li><i class="icon fa fa-book"></i> Blog</li>
<li><i class="icon fa fa-pencil"></i> Write a Blog</li>
<? if ($_SESSION['user']['level'] >= 2): ?>
<li><i class="icon fa fa-pencil"></i> Admin</li>
<? endif ?>
<? if ($_SESSION['user']['first_name']): ?>
<li><i class="icon fa fa-sign-in"></i> Logout</li>
<? else: ?>
<li><i class="icon fa fa-sign-in"></i> Login</li>
<li><i class="icon fa fa-pencil"></i> Register</li>
<? endif ?>
</ul>
</div>
</div>
</nav>
</div>
</header>
It is probably something easy, I do tend to over complicate things! Thank you in advance.
Here's one approach where variables are set and validated before processing markup content. May provide a clear, clean code.
<?php
// 1. get session user object
$user = (isset($_SESSION['user'])) ? $_SESSION['user'] : null;
// 2. set vars
if($user) {
if(isset($user['first_name'])) {
$first_name = $user['first_name'];
}
if(isset($user['level'])) {
$level = $user['level'];
}
}
// 3. set flag (optional) or access $level directly
if(isset($level)) {
$isAdmin = ($level === "Admin") ? true: false;
}
// normal user: Hello (name of user), Home, Blog, Write a blog, Logout,
// admin logs : Hello (name of user), Home, Blog, Write a blog, Admin, Logout,
?>
and the markups...
<header>
<div class="wrap-header zerogrid">
<div id="logo"><img src="/assets/images/logo_blog.png"/></div>
<nav>
<div class="wrap-nav">
<div class="menu">
<ul class="list-unstyled">
<!-- code omited -->
<?php
if(isset($isAdmin) and $isAdmin) {
// display markup for Admin <li>
}
?>
</ul>
</div>
</div>
</nav>
</div>
</header>
Hope this helps.
Thank you for your replies. It really was something simple solved with an if statement:
<nav>
<div class="wrap-nav">
<div class="menu">
<ul class="list-unstyled">
<? if ($_SESSION['user']['first_name']): ?>
<li><i class="icon fa fa-user"></i> Hello <?= $_SESSION['user']['first_name'] ?></li>
<? endif ?>
<li><i class="icon fa fa-home"></i> Home</li>
<li><i class="icon fa fa-book"></i> Blog</li>
<? if ($_SESSION['user']['level'] < 2): ?>
<li><i class="icon fa fa-pencil"></i> Write a Blog</li>
<? else: ?>
<li><i class="icon fa fa-pencil"></i> Admin</li>
<? endif ?>
<? if ($_SESSION['user']['first_name']): ?>
<li><i class="icon fa fa-sign-in"></i> Logout</li>
<? else: ?>
<li><i class="icon fa fa-sign-in"></i> Login</li>
<li><i class="icon fa fa-pencil"></i> Register</li>
<? endif ?>
</ul>
</div>
</div>
</nav>
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?