Listing of only Subcategories (and their contents) with fewer than X items

More
6 years 1 month ago #72098 by Ninjakitten
Having ended up with quite a lot of subcatgories in one category, I decided I could make the menu tidier by gathering all the subcategories with fewer than 10 items under an 'Other' heading. I have the code that arranges the menu items working, but what I want it to link to is essentially a Flexicontent 'Categories' menu type (i.e., same layout as the menu items that go to one of those) which shows only the subcategories with fewer than 10 items.

As an example, let's say I had a category 'Pets', with subcategories of 'Cats' (25 items), 'Dogs' (20 items), 'Birds' (8 items), 'Lizards' (4 items), and 'Peeves' (2 items). My menu would now say:
Cats (25)
Dogs (20)
Other (14)

When someone clicks 'Other', I want it to list the subcategories of Birds, Lizards, and Peeves, and then all the items from all three of those categories.

I can't just make a 'Categories' menu item that calls those three categories, because if two more 'Birds' items are added, I want it to automatically move that subcat out of 'Other' as it will now pass the test. The actual dropdown isn't an issue, but creating what 'Other' should link to is.

What would be the best way to do this? The modules don't have an option to select based on number of items in the category, so the simple ways won't work.

* Is there a simple way to create/add a new menu type, so that I could clone the categories one into a version that gates by item total?
* Or is there a proper way to call a layout from php code called in an article, so that I could make an article that would grab the correct subcats/items from the db and format them in the same way as the current categories menu items? (I would rather not just recreate the same look, in case I ever change it.)
* Might there be some far easier way I just haven't seen/thought of?

Thanks for your time!

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago #72128 by ggppdk
Hello

do you want to list sub-categories and then under every sub-category list the items of every category ?

do you want to include only categories that have less than NN (e.g. less than 10) items ?


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago - 6 years 1 month ago #72139 by Ninjakitten

ggppdk wrote: do you want to include only categories that have less than NN (e.g. less than 10) items ?

Yes. Well, technically, subcategories that have fewer than NN items within a given top level category. So, using my earlier example, if I were using the 'Pets' top level category, the page would include only items from subcategories of 'Pets' which have fewer than NN items.

ggppdk wrote: do you want to list sub-categories and then under every sub-category list the items of every category ?

Not precisely. I do want all the items from the subcategories which qualify to be listed, but I want to use the same layout I use for a menu item that links to a category with subcategories. In this case, that isn't literally a list of 'subcategory, its items; next subcategory, its items, etc.' It's actually a list of all the items, in which each one is marked by which subcategories it belongs to.

But ideally, I'd like it not to matter how the data is going to be displayed -- to be able to change layouts for it if I want to without recoding the whole thing.

If it could use the same actual layout file that the menu item is using, that would be perfect.

Thank you for your response!

Edited to add:


If I have to do it as a special page rather than a menu item type, I'm reasonably sure I could write a DB query to get the appropriate subcategories and their items all right -- what I'm finding really tricky is figuring out how I might be able to pipe the results through the layout file.

Whereas if it were a menu item type, the layout use is presumably trivial -- but the instructions I've found for making menu item types assume it's your own component, and I wouldn't want it to get overwritten later if I did all that work. It looks fairly complicated.

If there's a third, better way, which hasn't yet occurred to me, I will happily try it!
Last edit: 6 years 1 month ago by Ninjakitten. Reason: Addition!

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago #72386 by Ninjakitten

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago #72387 by ggppdk
Hello

your usage scenario is related to the DB query that selects items in category view (mulit-item views)

-- no related options are implemented for such behaviour of the DB query
-- also the other items would need to be collected under 'other' category

i have an idea on how to implement this in the CORE
as we have a cached estimate for items in categories that could be used to create fast queries
(updated every NN minutes)

but there is no wild need for this , other things are of higher priority

you can implement a solution for your web-site
and the contribute it back to the project via a PR in github
Code:
global $globalcats;


My suggestion is this
1. hide the "sub-categories" list in category view
2. create a filtering module and in it add the categories filter, and display filter as checkboxes, which has an instant text-search filter and scrolling when the list of checkboxes gets too large (just you need to install v3.2.1.13, because the instant text fillter is not shown in v3.2.1.12 and previous)


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.381 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline