- Posts: 2
COMMUNITY FORUM
Hide Empty Categories
- vvhorus
-
Topic Author
- Offline
- New Member
Less
More
11 years 3 months ago #124574
by vvhorus
Hide Empty Categories was created by vvhorus
Hello!
I'm using K2 on a couple of sites and I love it. Thank you!
On one of these sites, I have the need to hide all sub-categories that do not contain any items. My site displays content based on user permissions. Not all of my users need to see all the content, only what pertains to them. Because of this, some sub-categories will appear to be empty for some users. I need to hide sub-categories when they have zero items.
I have extensively searched this forum looking for the answer. There are a few postings here which vaguely try to explain the general idea of what needs to be done, but lack on specifics. It appears to be an easy solution, yet no one has come forward with a viable way to accomplish this. Please be aware that the vast majority of K2 users are not PHP coders, and things like "I would try to add up the values of count and test the result for >0 " do not mean much to most of us.
A user named olsen suggested something like this, which I believe is going in the right direction:
I am sure that I'm not alone in requiring something like this. This could be a great addition to the core K2 functionality in future versions.
Could someone please eleborate further on this? Are there any other way to accomplish this? Any specific help (place "this" code in line ???) would be greatly appreciated!
Thank you!!
I'm using K2 on a couple of sites and I love it. Thank you!
On one of these sites, I have the need to hide all sub-categories that do not contain any items. My site displays content based on user permissions. Not all of my users need to see all the content, only what pertains to them. Because of this, some sub-categories will appear to be empty for some users. I need to hide sub-categories when they have zero items.
I have extensively searched this forum looking for the answer. There are a few postings here which vaguely try to explain the general idea of what needs to be done, but lack on specifics. It appears to be an easy solution, yet no one has come forward with a viable way to accomplish this. Please be aware that the vast majority of K2 users are not PHP coders, and things like "I would try to add up the values of count and test the result for >0 " do not mean much to most of us.
A user named olsen suggested something like this, which I believe is going in the right direction:
olsen wrote: Well, actually it can be done with a template override. Modifying file category.php with an if statement in the subcategory loop to check if the subcategory has items on it.
Something like:
<?php if ($subcategory->numofitems > 0) :?> LOOP <?php endif ;?>
I am sure that I'm not alone in requiring something like this. This could be a great addition to the core K2 functionality in future versions.
Could someone please eleborate further on this? Are there any other way to accomplish this? Any specific help (place "this" code in line ???) would be greatly appreciated!
Thank you!!
Please Log in or Create an account to join the conversation.
- Yiota
-
- Visitor
11 years 3 months ago #124575
by Yiota
Replied by Yiota on topic Re: Hide Empty Categories
Hello,
In order to make the above modification you first need to create K2 template overrides. Read here: getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates on how overrides work.
Then you need to edit category.php file in about line 80, after the foreach is opened, and add this code
close the if statement right before the endforeach;
In order to make the above modification you first need to create K2 template overrides. Read here: getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates on how overrides work.
Then you need to edit category.php file in about line 80, after the foreach is opened, and add this code
<?php if ($subCategory->numOfItems > 0) : ?>
....
<?php endif; ?>
close the if statement right before the endforeach;
Please Log in or Create an account to join the conversation.
- vvhorus
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 2
11 years 3 months ago #124576
by vvhorus
Replied by vvhorus on topic Re: Hide Empty Categories
SOLVED!
I had the template override part done. I just needed to know where to place the code in category.php. It works beautifully. Thank you very very much!
This could be something to add to future K2 releases...
I had the template override part done. I just needed to know where to place the code in category.php. It works beautifully. Thank you very very much!
This could be something to add to future K2 releases...
Please Log in or Create an account to join the conversation.
- Yiota
-
- Visitor
11 years 3 months ago #124577
by Yiota
Replied by Yiota on topic Re: Hide Empty Categories
You are welcome.
Please Log in or Create an account to join the conversation.
- MessageDJ
-
- Offline
- New Member
Less
More
- Posts: 15
10 years 8 months ago #124578
by MessageDJ
Replied by MessageDJ on topic Re: Hide Empty Categories
to bad you guys do not subscribe a more exact way to implement this... have tried everything...
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Platinum Member
Less
More
- Posts: 8743
10 years 8 months ago #124579
by Lefteris
Replied by Lefteris on topic Re: Hide Empty Categories
@MessageDJ
I don't think there is more exact way than this getk2.org/community/English-K2-Community/189642-Hide-Empty-Categories#189695 . If this doesn't make sense to you then probably it would be better to ask a developer to do it.
I don't think there is more exact way than this getk2.org/community/English-K2-Community/189642-Hide-Empty-Categories#189695 . If this doesn't make sense to you then probably it would be better to ask a developer to do it.
Please Log in or Create an account to join the conversation.