Answer the question
In order to leave comments, you need to log in
How to make multiple product categories on homepage?
To display products on the main page, I use the "Recommendations" (featured) module.
There was a need to place all products on one main page, dividing them into categories. It looks like this:
The fact is that the module does not support categories. Initially, it can display all the products at once, without separating them in any way.
The division that is in the picture above, I achieved by copying the code in the featured.tpl file:
<!--Кровати-->
<div class="heading_title">
<?php echo $heading_title; ?>
<a id="button-to-target-1" class="categories_boxes">
Кровати
</a>
<a id="button-to-target-2" class="categories_boxes">
Постельное бельё
</a>
<a id="button-to-target-3" class="categories_boxes">
Аксессуары
</a>
</div>
<hr>
<div id="target-el-1" class="categories_text">
<a style="color: #444">
Кровати
</a>
</div>
<div class="row">
<?php foreach ($products as $product) { ?>
<div class="product-layout col-lg-3 col-md-3 col-sm-6 col-xs-12">
<div class="product-thumb transition">
<div class="image"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" /></a></div>
<div class="caption">
<h3 align="center"><b><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></b></h3>
<hr>
<?php if ($product['rating']) { ?>
<div class="rating">
<?php for ($i = 1; $i <= 5; $i++) { ?>
<?php if ($product['rating'] < $i) { ?>
<span class="fa fa-stack"><i class="fa fa-star-o fa-stack-2x"></i></span>
<?php } else { ?>
<span class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i><i class="fa fa-star-o fa-stack-2x"></i></span>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
<?php if ($product['price']) { ?>
<p class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price']; ?>
<?php } else { ?>
<span class="price-new"><?php echo $product['special']; ?></span> <span class="price-old"><?php echo $product['price']; ?></span>
<?php } ?>
<?php if ($product['tax']) { ?>
<?php } ?>
</p>
<?php } ?>
</div>
<div class="button-group">
<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button>
</div>
</div>
</div>
<?php } ?>
</div>
<!--Постельное бельё-->
<div id="target-el-2" class="categories_text">
<a style="color: #444">
Постельное бельё
</a>
</div>
<div class="row">
<?php foreach ($products as $product) { ?>
<div class="product-layout col-lg-3 col-md-3 col-sm-6 col-xs-12">
<div class="product-thumb transition">
<div class="image"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" /></a></div>
<div class="caption">
<h3 align="center"><b><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></b></h3>
<hr>
<?php if ($product['rating']) { ?>
<div class="rating">
<?php for ($i = 1; $i <= 5; $i++) { ?>
<?php if ($product['rating'] < $i) { ?>
<span class="fa fa-stack"><i class="fa fa-star-o fa-stack-2x"></i></span>
<?php } else { ?>
<span class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i><i class="fa fa-star-o fa-stack-2x"></i></span>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
<?php if ($product['price']) { ?>
<p class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price']; ?>
<?php } else { ?>
<span class="price-new"><?php echo $product['special']; ?></span> <span class="price-old"><?php echo $product['price']; ?></span>
<?php } ?>
<?php if ($product['tax']) { ?>
<?php } ?>
</p>
<?php } ?>
</div>
<div class="button-group">
<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button>
</div>
</div>
</div>
<?php } ?>
</div>
<!--Аксессуары-->
<div id="target-el-3" class="categories_text">
<a style="color: #444">
Аксессуары
</a>
</div>
<div class="row">
<?php foreach ($products as $product) { ?>
<div class="product-layout col-lg-3 col-md-3 col-sm-6 col-xs-12">
<div class="product-thumb transition">
<div class="image"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" /></a></div>
<div class="caption">
<h3 align="center"><b><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></b></h3>
<hr>
<?php if ($product['rating']) { ?>
<div class="rating">
<?php for ($i = 1; $i <= 5; $i++) { ?>
<?php if ($product['rating'] < $i) { ?>
<span class="fa fa-stack"><i class="fa fa-star-o fa-stack-2x"></i></span>
<?php } else { ?>
<span class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i><i class="fa fa-star-o fa-stack-2x"></i></span>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
<?php if ($product['price']) { ?>
<p class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price']; ?>
<?php } else { ?>
<span class="price-new"><?php echo $product['special']; ?></span> <span class="price-old"><?php echo $product['price']; ?></span>
<?php } ?>
<?php if ($product['tax']) { ?>
<?php } ?>
</p>
<?php } ?>
</div>
<div class="button-group">
<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button>
</div>
</div>
</div>
<?php } ?>
</div>
Answer the question
In order to leave comments, you need to log in
Dump the contents of $products with var_dump and see if there is something like category or category_id there. If not, it's easier to take another module. If there is, run all products in a loop and make an array with a list of categories or their id from them, then run through array_unique an array with a list of categories (if it is not unique) and in a loop for it (foreach $categories as $category) display only its products (for example, if $product['category'] = $category - display the product). But if the module does not provide for the display of categories, then most likely you will have to get into the opencart category controller and see how it takes data by category, because most likely you will need to display information about it, in addition to the category itself, such as the title, a link to the category, picture.... get ready to be
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question