- Posts: 2
COMMUNITY FORUM
Group items by subcategory
- Kelly
- Topic Author
- Offline
- New Member
Less
More
9 years 6 months ago #143866
by Kelly
Group items by subcategory was created by Kelly
Hello,
I have set up a catalog with the following category hierarchy:
I have a menu item that displays the Product Catalog category. I have this category set to "No" for Catalog Mode so it will display all items in the subcategories.
Is there a way to have the items grouped by subcategory on this page?
I am comfortable with editing custom K2 templates if that is where the answer lies.
Thanks for any help!
I have set up a catalog with the following category hierarchy:
- Product Catalog
- Category 1
- Category 2
- Category 3
- Etc...
I have a menu item that displays the Product Catalog category. I have this category set to "No" for Catalog Mode so it will display all items in the subcategories.
Is there a way to have the items grouped by subcategory on this page?
I am comfortable with editing custom K2 templates if that is where the answer lies.
Thanks for any help!
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
9 years 6 months ago #143917
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Group items by subcategory
Hello Kelly,
Unfortunately this is not possible.
You can use however the latests items from category view or K2 Content modules.
Unfortunately this is not possible.
You can use however the latests items from category view or K2 Content modules.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Josh Wilkinson
- Offline
- New Member
Less
More
- Posts: 14
9 years 2 months ago - 9 years 2 months ago #147328
by Josh Wilkinson
Hi, I know this post is about 4 months old but as Krikor said out of the box there is no way to do this. If you edit the category.php
and place the following code below it allows you to have the following structure
Subcategory 1
Replace the following:
Replace the above code with this below:
You can remove divs as needed this is just the divs I needed for my particular template.
I hope this helps someone else as it took me a while to figure this out.
Also I hope in future versions you will consider have an option to where the subcategories can either show up at the top like they currently do or have the subcategories show up with there corresponding category items beneath them.
Thanks,
Josh
Replied by Josh Wilkinson on topic Group items by subcategory
Kelly wrote: Hello,
I have set up a catalog with the following category hierarchy:
- Product Catalog
- Category 1
- Category 2
- Category 3
- Etc...
I have a menu item that displays the Product Catalog category. I have this category set to "No" for Catalog Mode so it will display all items in the subcategories.
Is there a way to have the items grouped by subcategory on this page?
I am comfortable with editing custom K2 templates if that is where the answer lies.
Thanks for any help!
Hi, I know this post is about 4 months old but as Krikor said out of the box there is no way to do this. If you edit the category.php
and place the following code below it allows you to have the following structure
Subcategory 1
- item 1
- item 2
- item 1
- item 2
Replace the following:
<?php if($this->params->get('subCategories') && isset($this->subCategories) && count($this->subCategories)): ?>
<!-- Subcategories -->
<div class="itemListSubCategories">
<h3><?php echo JText::_('K2_CHILDREN_CATEGORIES'); ?></h3>
<?php foreach($this->subCategories as $key=>$subCategory): ?>
<?php
// Define a CSS class for the last container on each row
if( (($key+1)%($this->params->get('subCatColumns'))==0))
$lastContainer= ' subCategoryContainerLast';
else
$lastContainer='';
?>
<div class="subCategoryContainer<?php echo $lastContainer; ?>"<?php echo (count($this->subCategories)==1) ? '' : ' style="width:'.number_format(100/$this->params->get('subCatColumns'), 1).'%;"'; ?>>
<div class="subCategory">
<?php if($this->params->get('subCatImage') && $subCategory->image): ?>
<!-- Subcategory image -->
<a class="subCategoryImage" href="<?php echo $subCategory->link; ?>">
<img alt="<?php echo K2HelperUtilities::cleanHtml($subCategory->name); ?>" src="<?php echo $subCategory->image; ?>" />
</a>
<?php endif; ?>
<?php if($this->params->get('subCatTitle')): ?>
<!-- Subcategory title -->
<h2>
<a href="<?php echo $subCategory->link; ?>">
<?php echo $subCategory->name; ?><?php if($this->params->get('subCatTitleItemCounter')) echo ' ('.$subCategory->numOfItems.')'; ?>
</a>
</h2>
<?php endif; ?>
<?php if($this->params->get('subCatDescription')): ?>
<!-- Subcategory description -->
<p><?php echo $subCategory->description; ?></p>
<?php endif; ?>
<!-- Subcategory more... -->
<a class="subCategoryMore" href="<?php echo $subCategory->link; ?>">
<?php echo JText::_('K2_VIEW_ITEMS'); ?>
</a>
<div class="clr"></div>
</div>
</div>
<?php if(($key+1)%($this->params->get('subCatColumns'))==0): ?>
<div class="clr"></div>
<?php endif; ?>
<?php endforeach; ?>
<div class="clr"></div>
</div>
<?php endif; ?>
Replace the above code with this below:
<?php if($this->params->get('subCategories') && isset($this->subCategories) && count($this->subCategories)): ?>
<div class="subcategories">
<div class="subcategory-inner">
<?php foreach($this->subCategories as $key=>$subCategory): ?>
<h2 class="subcategory"><?php echo $subCategory->name; ?></h2>
<div class="subcategoryname" id="<?php echo $subCategory->name; ?>">
<?php if(isset($this->leading) && count($this->leading)): ?>
<?php foreach($this->leading as $key=>$item): ?>
<?php if($item->catid == $subCategory->id): ?>
<?php
// Load category_item.php by default
$this->item=$item;
echo $this->loadTemplate('item');
?>
<?php endif;?>
<?php endforeach; ?>
<div class="clearfix"></div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<div class="clearfix"></div>
</div>
<?php endif; ?>
You can remove divs as needed this is just the divs I needed for my particular template.
I hope this helps someone else as it took me a while to figure this out.
Also I hope in future versions you will consider have an option to where the subcategories can either show up at the top like they currently do or have the subcategories show up with there corresponding category items beneath them.
Thanks,
Josh
Last edit: 9 years 2 months ago by Josh Wilkinson.
Please Log in or Create an account to join the conversation.
- Kelly
- Topic Author
- Offline
- New Member
Less
More
- Posts: 2
9 years 2 months ago #147329
by Kelly
Replied by Kelly on topic Group items by subcategory
Thank you for the reply!
I ended up using K2 content modules to display the products on the main Product Catalog menu item. One module for each subcategory. It works, but, I'd prefer it to be grouped by subcategory like I originally described. I'll try your solution when time allows.
Thanks again!
I ended up using K2 content modules to display the products on the main Product Catalog menu item. One module for each subcategory. It works, but, I'd prefer it to be grouped by subcategory like I originally described. I'll try your solution when time allows.
Thanks again!
Please Log in or Create an account to join the conversation.
- Josh Wilkinson
- Offline
- New Member
Less
More
- Posts: 14
9 years 2 months ago #147330
by Josh Wilkinson
Replied by Josh Wilkinson on topic Group items by subcategory
No problem glad it was helpful!
Just another thing I only put the things in the template I needed if you need to add addtional things such as the subcategory description below the line
You would add the following, you can do the same with any other thing you want to add back into the subcategory options.
Also I forgot to mention earlier further down in your code it will be loading the following below again you will need to comment this line out or it will load the category items 2 times.
Just another thing I only put the things in the template I needed if you need to add addtional things such as the subcategory description below the line
<h2 class="subcategory"><?php echo $subCategory->name; ?></h2>
You would add the following, you can do the same with any other thing you want to add back into the subcategory options.
<?php if($this->params->get('subCatDescription')): ?>
<!-- Subcategory description -->
<p><?php echo $subCategory->description; ?></p>
<?php endif; ?>
Also I forgot to mention earlier further down in your code it will be loading the following below again you will need to comment this line out or it will load the category items 2 times.
<?php
// Load category_item.php by default
$this->item=$item;
echo $this->loadTemplate('item');
?>
Please Log in or Create an account to join the conversation.
- Mark
- Offline
- New Member
Less
More
- Posts: 5
7 years 3 months ago #163600
by Mark
Replied by Mark on topic Group items by subcategory
I second this feature request. It's actually the reason why I installed K2 in the first place.
I ended up moving the "Listed in (Category)" php code to the top in the category_item.php file but then the Category Title just shows up on top of each Item.
I then ended up hiding the Category Title (with CSS) on all Items except for Featured Items (featured the first items in my categories) since I couldn't even use a ":first-child" CSS instance. This is not really a good solution since you have to keep track of which Items are at the top of the Categories.
Thanks for the provided hack above but at this point I'm pretty exhausted from the whole thing. Please make this a feature!
I ended up moving the "Listed in (Category)" php code to the top in the category_item.php file but then the Category Title just shows up on top of each Item.
I then ended up hiding the Category Title (with CSS) on all Items except for Featured Items (featured the first items in my categories) since I couldn't even use a ":first-child" CSS instance. This is not really a good solution since you have to keep track of which Items are at the top of the Categories.
Thanks for the provided hack above but at this point I'm pretty exhausted from the whole thing. Please make this a feature!
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
7 years 3 months ago #163618
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Group items by subcategory
This is already available as the "Latest items from categories" Menu item.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Mark
- Offline
- New Member
Less
More
- Posts: 5
7 years 3 months ago #163622
by Mark
Replied by Mark on topic Group items by subcategory
I am using "Latest items from categories" but when I have Items listed on one page from several sub-categories, I am not able to get the sub-category title at the top of each listed Item sections:
Main Category Title
Sub-Category Title
Item 1 with intro content
Item 2 with intro content
Sub-Category2
Item 1 with intro content
Item 2 with intro content
Main Category Title
Sub-Category Title
Item 1 with intro content
Item 2 with intro content
Sub-Category2
Item 1 with intro content
Item 2 with intro content
Please Log in or Create an account to join the conversation.