Is this possible to put this in dropdown filter? I'm using Wordpress Theme.
<div class="container mb-half">
<ul class="nav nav-<?php echo $filter;?> nav-<?php echo $filter_align ;?> nav-<?php echo $filter_nav;?> nav-uppercase filter-nav">
<li class="active"><?php echo __('All','custom_theme'); ?></li>
<?php
$tax_terms = get_terms('featured_item_category');
foreach ($tax_terms as $key => $value) {
?><li><?php echo $value->name; ?></li><?php
}
?>
</ul>
</div>
Related
I have data collection and getting detail by foreach loop, which is working fine.
But I want 3 in a single inside foreach loop.
For example:
<ol>
<div>
<li></li>
<li></li>
<li></li>
</div>
<div>
<li></li>
<li></li>
<li></li>
</div>
<div>
<li></li>
<li></li>
<li></li>
</div>
</ol>
I am using below code for displaying the data:
<ol class="product-items widget-viewed-grid">
<?php $iterator = 1; ?>
<div id="mp-list-items-<?php echo $block->getSliderId(); ?>" class="owl-carousel owl-theme">
<?php foreach ($items as $_item): ?>
<?php echo ($iterator++ == 1) ? '<li class="product-item product-slider"">' : '</li><li class="product-item product-slider"">' ?>
<div class="slider-product-item-info">
<div class="product details slider-product-item-details">
<strong class="product name product-item-name">
<a title="<?php echo $block->escapeHtml($_item->getName()) ?>" href="<?php echo $block->getProductUrl($_item) ?>">
<?php echo $block->escapeHtml($_item->getName()) ?>
</a>
</strong>
</div>
</div>
<?php echo ($iterator == count($items) + 1) ? '</li>' : '' ?>
<?php endforeach ?>
</div>
</ol>
echo "<ol>";
for( $i=0; $i<3; $i++ ) {
echo "<div>";
for($j=0; $j<3; $j++) {
echo "<li>";
echo "</li>";
}
echo "</div>";
}
echo "</ol>";
You have to use nested loops. Outer loop for product <div> and inner loop for product items <li>.
For Example
foreach($products as $product){
echo "<div class='product'>";
//Now you can call sql query to get items by product id
foreach($items as $item){
echo "<li class='list-item'>" . $item->name . "</li>"; //assuming $item has name property
} //end of inner loop
echo "<div class='product'>";
} //end of outer loop
I'm attempting to add a for loop to a php menu that will add a tertiary level to a currently existing WP menu. Unfortunately, the only editable amount of content is that posted below, so please bear with me on this one.
I'm just wondering, before I attempt to implement this code, if anyone can tell me if it will actually work, of if you assume it'll break everything.
What I've done is to take the same semantic forloop that was written for the secondary (or 'sub_nav') menu items, and repeat it in attempts to dynamically generate third level (or 'tert_nav') menu items.
<div class="main-menu-sub-navigation">
<?php
$main_nav_items = wp_get_nav_menu_items(2);
$sub_nav = array();
foreach ($main_nav_items as $item) {
if($item->menu_item_parent !== '0'){
$parent_id = $item->menu_item_parent;
$sub_nav[$parent_id][] = array('item' => $item);
}
}
$tert_nav = array();
foreach ($sub_nav_items as $item) {
if($item->menu_item_parent !== '0'){
$parent_id = $item->menu_item_parent;
$tert_nav[$parent_id][] = array('item' => $item);
}
}
?>
<div class="sub-nav-inner">
<?php foreach ($sub_nav as $key => $value) { ?>
<ul class="nav sub-nav" data-parent="<?php print $key; ?>">
<?php foreach ($value as $item) { ?>
<?php if(isset($_GET['archive'])): ?>
<li class="menu-item-<?php print $item['item']->object_id; ?> <?php print ($item['item']->title == 'Archives') ? 'current-menu-item' : 'menu-item'; ?>"><a href="<?php print $item['item']->url; ?>"><?php print $item['item']->title; ?>
<?php foreach ($tert_nav as $key => $value) { ?>
<ul class="nav tert-nav" data-parent="<?php print $key; ?>">
<?php foreach ($value as $item) { ?>
<?php if(isset($_GET['archive'])): ?>
<li class="menu-item-<?php print $item['item']->object_id; ?> <?php print ($item['item']->title == 'Archives') ? 'current-menu-item' : 'menu-item'; ?>"><?php print $item['item']->title; ?></li>
<?php else: ?>
<li class="menu-item-<?php print $item['item']->object_id; ?> <?php print ($item['item']->object_id == get_the_ID()) ? 'current-menu-item' : 'menu-item'; ?>"><?php print $item['item']->title; ?></li>
<?php endif; ?>
<?php } ?>
</ul>
<?php } ?>
</a></li>
<?php else: ?>
<li class="menu-item-<?php print $item['item']->object_id; ?> <?php print ($item['item']->object_id == get_the_ID()) ? 'current-menu-item' : 'menu-item'; ?>"><a href="<?php print $item['item']->url; ?>"><?php print $item['item']->title; ?>
<?php foreach ($sub_nav as $key => $value) { ?>
<ul class="nav tert-nav" data-parent="<?php print $key; ?>">
<?php foreach ($value as $item) { ?>
<?php if(isset($_GET['archive'])): ?>
<li class="menu-item-<?php print $item['item']->object_id; ?> <?php print ($item['item']->title == 'Archives') ? 'current-menu-item' : 'menu-item'; ?>"><?php print $item['item']->title; ?></li>
<?php else: ?>
<li class="menu-item-<?php print $item['item']->object_id; ?> <?php print ($item['item']->object_id == get_the_ID()) ? 'current-menu-item' : 'menu-item'; ?>"><?php print $item['item']->title; ?></li>
<?php endif; ?>
<?php } ?>
</ul>
<?php } ?>
</a></li>
<?php endif; ?>
<?php } ?>
</ul>
<?php } ?>
</div>
Any help would be so very greatly appreciated. Thank you!!
on each products page I currently have displayed the products subcategory, but only one level deep. So if in categories I have Brother > MFC > B4564 > TN450.... and I am on the TN450's product page, down below it will only show BN4564 . I need it also show The mfc and the brother part. I am not sure how to do this.. any ideas? here is my current code.
.TPL file
<!-- Display product categories -->
<?php foreach ($catprod as $catp)
{
?><?php echo $catp['name']; ?> <?php
}`
controller .php file
$data['catprod'] = array();
$product_category = $this->model_catalog_product->getCategories($this->request->get['product_id']);
foreach ($product_category as $prodcat)
{
$category_info = $this->model_catalog_category->getCategory($prodcat['category_id']);
if ($category_info)
{
$data['catprod'][] = array('name' => $category_info['description'],'href' => $this->url->link('product/category', 'path=' . $category_info['category_id']));
}
}`
which version of opencart?
this should work for version 1:
open catalog/view/theme/default/template/module/category.tpl
remove its contents and insert:
<div class="box" id="categories-menu">
<div class="box-heading"><?php echo $heading_title; ?></div>
<div class="box-content">
<ul class="box-category" id="box-category">
<?php foreach ($categories as $category) { ?>
<li>
<?php if ($category['category_id'] == $category_id) { ?>
<a href="<?php echo $category['href']; ?>" class="active list-group-item" ><?php echo $category['name']; ?></a>
<?php } else { ?>
<?php echo $category['name']; ?>
<?php } ?>
<?php if ($category['children']) { ?>
<ul class="submenu">
<?php foreach ($category['children'] as $child) { ?>
<li>
<?php if ($child['category_id'] == $child_id) { ?>
- <?php echo $child['name']; ?>
<?php } else { ?>
- <?php echo $child['name']; ?>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
I want to Show Multilevel Dropdown menu in opencart 2.0 category module
Menu>submenu>submenu1>submenulevel2>level3>
Can you please explain if you want this in the Admin area or the customer front end?
In which case in category.tpl just modify or write something like this:
<?php if ($categories) { ?>
<?php if (count($categories) <= 5) { ?>
<div class="col-sm-3 nosidepadding">
<ul>
<?php foreach ($categories as $category) { ?>
<li><?php echo $category['name']; ?></li>
<?php } ?>
</ul>
</div>
<?php } else { ?>
<?php foreach (array_chunk($categories, ceil(count($categories) / 4)) as $categories) { ?>
<div class="col-sm-3 nosidepadding">
<ul>
<?php foreach ($categories as $category) { ?>
<li><?php echo $category['name']; ?></li>
<?php } ?>
</ul>
</div>
<?php } ?>
<?php } ?>
<?php } ?>
This is the loop I want to limit this to 2 outputs and create another loop for further outputs please help.. I am a beginner
Enter code here
<?php if ($informations) { ?>
<div class="column">
<h3>
<?php echo $text_information; ?>
</h3>
<ul>
<?php foreach ($informations as $information){ ?>
<li><a href="<?php echo $information['href']; ?>">
<?php echo $information['title']; ?>
</a></li>
<?php } ?>
</ul>
</div>
<?php } ?>
Try this. .
<?php if ($informations) { ?>
<div class="column">
<h3><?php echo $text_information; ?></h3>
<ul>
<?php
$i=1;
foreach ($informations as $information){
if($i==2)
{
break;
}
?>
<li><?php echo $information['title']; ?></li>
<?php
$i++;
} ?>
</ul>
</div>
<?php } ?>
For other values . .
<?php if ($informations) { ?>
<div class="column">
<h3><?php echo $text_information; ?></h3>
<ul>
<?php
$i=1;
foreach ($informations as $information){
if($i<2)
{
continue;
}
?>
<li><?php echo $information['title']; ?></li>
<?php
$i++;
} ?>
</ul>
</div>
<?php } ?>
Bit vague but I guess you are looking for array_chunk,
$new_array = array_chunk($informations, 2, true);