I have my menu styled with Bootstrap. My dropdown menu was like that with html+bootsrap:
`
<div class="container">
<div class="row">
<ul class="col-sm-3">
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
<ul class="col-sm-3">
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
<ul class="col-sm-3">
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
<ul class="col-sm-3">
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</div>
</div>
I used the class col-sm-3 every 4 items to achieve that.
But i cant do that in php cause i am using foreach loop and the result is like this one:
I tried with col-sm-3 but not..
<div class="collapse navbar-collapse btnCollapse">
<ul class="nav navbar-nav">
<li>Home</li>
<?php foreach ($navItems as $item) { ?>
<li class="dropdown">
<?php echo $item['title']; ?><span class="caret"></span>
<?php if(isset($item['dropdown'])){ ?>
<ul class="dropdown-menu" role="menu">
<div class="container">
<div class="row">
<ul class="col-sm-3">
<?php foreach($item['dropdown'] as $subitem) { ?>
<li><?php echo $subitem['title'] ?></li>
<?php }; ?>
</ul>
</div>
</div>
</ul>
<?php }; ?>
</li>
<?php }; ?>
</ul>
</div>
WHats the way to achieve that?
Maybe should I use For loop instead of foreach? I dont know..
Any feedback?
<div class="collapse navbar-collapse btnCollapse">
<ul class="nav navbar-nav">
<li>Home</li>
<?php foreach ($navItems as $item) { ?>
<li class="dropdown">
<?php echo $item['title']; ?><span class="caret"></span>
<?php if(isset($item['dropdown'])){ ?>
<ul class="dropdown-menu" role="menu">
<div class="container">
<div class="row">
<?php $i = 0; foreach($item['dropdown'] as $subitem) {
if($i%4==0){
echo "<ul class="col-sm-3">";
} ?>
<li><?php echo $subitem['title'] ?></li>
<?php if($i%4==3){
echo "</ul>";
}
$i++;
}; ?>
</div>
</div>
</ul>
<?php }; ?>
</li>
<?php }; ?>
</ul>
</div>
In your desired output you need 4 colums, so I devided menu items by 4 to put column i.e. if($i%4==0) for starting <ul> and if($i%4==3) for ending </ul>.
Related
I have a screen like this and I get this image using 3 separate divs and ul-li. The data inside are fixed data that I wrote manually.
<div class="cards">
<div class="card shadow">
<ul>
<li class="pack">1 Points</li>
<li id="one" class="price bottom-bar">$1</li>
<li class="bottom-bar">1 Points</li>
</ul>
</div>
<div class="card active">
<ul>
<li class="pack">2 Points</li>
<li id="two" class="price bottom-bar">$2</li>
<li class="bottom-bar">2 Points</li>
</ul>
</div>
<div class="card shadow">
<ul>
<li class="pack">3 Points</li>
<li id="two" class="price bottom-bar">$3</li>
<li class="bottom-bar">3 Points</li>
</ul>
</div>
</div>
There is no problem so far, but when I bring this data from the database and retrieve it with foreach, that is, when it creates the ul-li tags itself, it gets the following image.
<div class="cards">
<div class="card shadow">
<ul>
<?php
foreach($package_types as $package_type){
echo '<li class="pack">'.$package_type['package_name'].'</li>';
echo '<li class="price bottom-bar">₺'.$package_type['amount'].'</li>';
echo '<li class="bottom-bar">'.$package_type['package_name'].'</li>';
}
?>
</ul>
</div>
</div>
How can I get the image in the first photo when I get the data with Foreach?
Try this
<div class="cards">
<?php
foreach ($package_types as $package_type) { ?>
<div class="card shadow">
<ul>
<?php
echo '<li class="pack">'.$package_type['package_name'].'</li>';
echo '<li class="price bottom-bar">₺'.$package_type['amount'].'</li>';
echo '<li class="bottom-bar">'.$package_type['package_name'].'</li>';
?>
</ul>
</div>
<? } ?>
</div>
You'll have to decide which one of those div tags with class card will also have the class active instead of the class shadow.
I'm editing a website, and this site uses data-groups, of which I'm not familiar (enough) with.
The current result is:
• In K2, I have items in categories, subcategories, and sub-subcategories.
• On the page of the items, there is a horizontal lign, showing each subcategory.
• On that page, I added a dropdown menu under one subcategory. In that dropdown, I have a few sub-subcategories. I would like that when I click on that sub-subcategory, it will show the items from that sub-subcategory.
What do I need to do to make this work?
If I need to post more, feel free to ask, and sorry.
I'll try to explain as good as possible:
Category.php
defined('_JEXEC') or die;
?>
<p style="text-align:center;font-weight:bold;font-size:120%;padding:1%;background:#007dbe;color:white;margin:1% 0 0.95% 0;">OUTLET</p>
<!--<img src="https://i.ibb.co/3dk77DK/outlet3.png" style="margin: 0 0 1% 0;">-->
<div class="centered-pills" style="width:98%;margin:0 auto;background:#474747;">
<ul class="nav nav-pills" id="outlet">
<li class="filterTitle">Filter op:</li>
<li class="active" id="pointer">All</li>
<li class="active" id="drop-a-down">Example
<ul class="drop-a-content">
<div class="column-outlet">
<ul><strong>Tools</strong>
<li class="force-css" data-group="Light">Tool 1</li>
<li class="force-css" data-group="Light">Tool 2</li>
<li class="force-css" data-group="Light">Tool 3</li>
</ul>
<ul><strong>Light</strong>
<li class="force-css" data-group="Light">Light 1</li>
<li class="force-css" data-group="Floor">Light 2</li>
<li class="force-css">Light 3</li>
<li class="force-css">Light 4</li>
</ul>
<ul><strong>Tools</strong>
<li class="force-css">Manual tools</li>
<li class="force-css">Electric tools</li>
</ul>
</div>
<div class="column-outlet">
<ul><strong>Other</strong>
<li class="force-css">Other 1</li>
<li class="force-css">Other 2</li>
<li class="force-css">Other 3</li>
</ul>
<ul><strong>Roof</strong>
<li class="force-css">Roof 1</li>
<li class="force-css">Roof 2</li>
<li class="force-css">Roof 3</li>
<li class="force-css">Roof 4</li>
</ul></div>
</ul>
</li>
<li class="active" id="drop-a-down">Animals
<ul class="drop-a-content">
<div class="column-outlet">
<ul><strong>Blocks</strong>
<li class="force-css">Block 1</li>
<li class="force-css">Block 2</li>
<li class="force-css">Block 3</li>
</ul>
<li class="active" data-group="Category-2">Cats</li>
<li class="active" data-group="Category-3">Dogs</li>
<li class="active" data-group="Category-4">Birds</li>
<li class="active" data-group="Category-5">Elephants</li>
<li class="active" data-group="Category-6">Tigers</li>
<li class="active" data-group="Category-7">Lions</li>
<li class="active" data-group="Category-8">Other</li>
<?php foreach($this->subCategories as $key=>$subCategory): ?>
<li data-group="<?php echo $subCategory->name; ?>"><?php echo $subCategory->name; ?></li>
<?php endforeach; ?>
</ul>
</div>
<div style="text-align:center;margin-top:2%;">
Get your products now!
</div>
<div style="clear:both;"></div>
<div class="inner">
<div class="row" style="margin-top:-5%;">
<?php if($this->params->get('subCategories') && isset($this->subCategories) && count($this->subCategories)): ?>
<div class="col-md-12 col-xs-12">
<div class="centered-pills" style="width:98%;margin:0 auto;">
<ul class="nav nav-pills">
<li class="filterTitle">Filter:</li>
<li class="active" data-group="All">Alle</li>
<?php foreach($this->subCategories as $key=>$subCategory): ?>
<li data-group="<?php echo $subCategory->name; ?>"><?php echo $subCategory->name; ?></li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php else: ?>
<div class="col-md-12 col-xs-12">
<p class="text-center" style="display:none;">Promotions in: <span class="divider"></span><strong><?php echo $this->category->name; ?></strong> <span class="divider"></span>Show all products</p>
</div>
<?php endif; ?>
<?php if(isset($this->leading) && count($this->leading)): ?>
<ul id="grid">
<?php foreach($this->leading as $key=>$item): ?>
<?php $this->item=$item; echo $this->loadTemplate('item'); ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<div style="text-align:center;margin-top:2%;font-style:italic;font-size:75%;">
All products are property of us.
</div>
</div>
<?php if($this->params->get('catDescription')): ?>
<div class="row">
<div class="col-md-12 col-xs-12">
<div class="disclaimer">
<?php echo $this->category->description; ?>
</div>
</div>
</div>
<?php endif; ?>
</div>
Jquery
/* initialize shuffle plugin */
var $grid = jQuery('#grid');
$grid.shuffle({
group: 'all',
itemSelector: '.portfolio-item', // the selector for the items in the grid
speed: 500 // Transition/animation speed (milliseconds)
});
/* reshuffle when user clicks a filter item */
jQuery('.nav-pills li').click(function (e) {
e.preventDefault();
// set active class
jQuery('.nav-pills li').removeClass('active');
jQuery(this).addClass('active');
// get group name from clicked item
var groupName = jQuery(this).attr('data-group');
// reshuffle grid
$grid.shuffle('shuffle', groupName );
});
});
How to make some menu tab option is invisible if user is not Admin, eg: if ['user_level']>=5
<a class="navbar-brand" href="#">CBS</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">DTC</li>
<li>View Proposal</li>
<li>Users details</li>
</ul>
<ul class="nav navbar-nav navbar-right">
I want to make only home.php menu tap visible to user only. Admin can see all the menu tab.
eg screen shot
Server side in php you can conditionally echo the related element.
Assuming you user auth is assigned to $userAuth var you can eg:
<a class="navbar-brand" href="#">CBS</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<?php if ( $userAuth == 'Admin' ) {
echo '<li class="active">DTC</li>';
}
?>
<li>View Proposal</li>
<li>Users details</li>
</ul>
<ul class="nav navbar-nav navbar-right">
You can do with 2 methods:
1) You have to give class hidden like this:
<style type="text/css">
.hidden {
display: none;
}
</style>
<?php
if ($user_level>=5) {
$hide = "hidden";
} else {
$hide = "";
}
?>
<a class="navbar-brand" href="#">CBS</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active <?=$hide?>">DTC</li>
<li class="<?=$hide?>">View Proposal</li>
<li class="<?=$hide?>">Users details</li>
</ul>
<ul class="nav navbar-nav navbar-right">
2) if else condition:
<a class="navbar-brand" href="#">CBS</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<?php if ($user_level>=5) { ?>
<li class="active">DTC</li>
<?php } else { ?>
<li class="active">DTC</li>
<li>View Proposal</li>
<li>Users details</li>
<?php } ?>
</ul>
<ul class="nav navbar-nav navbar-right">
Don't duplicate code - it is first rule. So better is to wrote:
(i persume that ['user_level'] is some value in array(); - here I call this array $user:
<a class="navbar-brand" href="#">CBS</a>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<!--first of all check if you get $user values-->
<?php if (isset($user)): ?>
<!-- display common elements for ALL USERS -->
<li class="active">DTC</li>
<!-- elements only for admins - users with level greater then 5-->
<?php if ($user['user_level'] >= 5): ?>
<li>View Proposal</li>
<li>Users details</li>
<?php endif; ?>
<?php endif; ?>
</ul>
Please help me custome wp_nav_menu with walker , thanks
<ul class="nav navbar-nav">
<li class="dropdown yamm-fw">PROJECT<b class="caret"></b>
<ul class="dropdown-menu">
<li class="grid-demo">
<div class="row">
<div class="col-sm-5">
<div class="col-sm-4">Introduction</div>
<div class="col-sm-4">Floor Plans A Type</div>
<div class="col-sm-4">Floor Plans B Type</div>
<div class="col-sm-4">Floor Plans C Type</div>
<div class="col-sm-4">Floor Plans D Type</div>
<div class="col-sm-4">Floor Plans E Type</div>
</div>
</div>
</li>
</ul>
</li>
how can i add some container tag after ul tag like <li class="grid-demo">
<div class="row">
<div class="col-sm-5">
<li>LOCATION</li>
<li>FEATURES</li>
<li class="dropdown yamm-fw">PAYMENT<b class="caret"></b>
<ul class="dropdown-menu">
<li class="grid-demo">
<div class="row">
<div class="col-sm-5">
<div class="col-sm-4">Playment T&C</div>
<div class="col-sm-4">Financial Services</div>
</div>
</div>
</li>
</ul>
</li>
<div class="spanLogo">aaa</div>
and how can i add one <div class="spanLogo">aaa</div> here
continue
<li class="dropdown yamm-fw">PUBLICITY<b class="caret"></b>
<ul class="dropdown-menu">
<li class="grid-demo">
<div class="row">
<div class="col-sm-5">
<div class="col-sm-4">News & Events</div>
<div class="col-sm-4">Testimonial</div>
</div>
</div>
</li>
</ul>
</li>
and here > > and how can i add one a tag with image like code above , thanks
<li>CONTACT</li>
<a class="navbar-brand" href="#"><img src="images/logo_paujar_top.jpg"/></a>
</ul>
I would like suggest you should used wp_get_nav_menu_items() function. In this function you can get separately all your menu title and url, So easily you manage your html.
Here is demonstration
<?php $menu_item = wp_get_nav_menu_items($menuId);
foreach($menu_item as $menu):?>
<a class="menu-iterm" href="<?php echo $menu->url;?>">
<?php echo $menu->title;?>
</a>
<?php endforeach;?>
For more information you get here http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items
Say I have the following div:
<div id="nav">
<ul>
<li class="navButton">Home</li>
<li class="navButton"><a href="http://www.freewebsitetemplates.com">Guitar
Bodies</a></li>
<li class="navButton"><a href="http://www.freewebsitetemplates.com">Guitar
Pickguards</a></li>
<li class="navButton">Contact Us</li>
</ul>
</div>
I would want this to be repeated a certain number of times so the resulting html would look like:
<div id="nav">
<ul>
<li class="navButton">Home</li>
<li class="navButton"><a href="http://www.freewebsitetemplates.com">Guitar
Bodies</a></li>
<li class="navButton"><a href="http://www.freewebsitetemplates.com">Guitar
Pickguards</a></li>
<li class="navButton">Contact Us</li>
</ul>
</div> <div id="nav">
<ul>
<li class="navButton">Home</li>
<li class="navButton"><a href="http://www.freewebsitetemplates.com">Guitar
Bodies</a></li>
<li class="navButton"><a href="http://www.freewebsitetemplates.com">Guitar
Pickguards</a></li>
<li class="navButton">Contact Us</li>
</ul>
</div> <div id="nav">
<ul>
<li class="navButton">Home</li>
<li class="navButton"><a href="http://www.freewebsitetemplates.com">Guitar
Bodies</a></li>
<li class="navButton"><a href="http://www.freewebsitetemplates.com">Guitar
Pickguards</a></li>
<li class="navButton">Contact Us</li>
</ul>
</div>
If the number was 3. What php command is used to do this sort of thing? (I know I use a for loop, but I mean the code in between)
Essentially what I will eventually have is something like this:
for each product
div product
text from product file
close div product
Thanks
Just use the foreach or while like this:
foreach($array as $value){
?>
<div>
whatever <?php other php here ?>
</div>
<?php
}
<div class='nav'>
<ul>
<?php foreach ($products as $product): ?>
<li class='navbutton'><?php echo $product->text; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
if you have multiple different divs, make a foreach loop for that too, if you want same div to repeat 3 times, wrap it around a for loop
<?
for ($results as $value) {
echo '<div id="nav">';
echo ' <ul>';
echo ' <li class="navButton">Home</li>';
echo ' <li class="navButton">'.$value['name1'].'</li>';
echo ' <li class="navButton">'.$value['name2'].'</li>';
echo ' <li class="navButton">Contact Us</li>';
echo ' </ul>';
echo ' </div>';
}
?>