We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: VZ Subcategories

Development and Programming

EliVZ's avatar
EliVZ
37 posts
16 years ago
EliVZ's avatar EliVZ

This may already exist, but I couldn’t find it. It outputs a pipe-delimited list of child categories of a particular parent category. I created it because I wanted an easy way to display only entries that are assigned to categories that are children of another category. I didn’t want to auto-assign the entries to the parent category (for one thing, I already had a bunch of entries in there that I would have had to go back and edit).

If you use this in the category parameter of your weblog:entries tag, you will also need to add parse=”inward” to weblog:entries.

Parameter: id - the id of the parent category to use.

Example:

{exp:weblog:entries weblog="news" category="{exp:vz_subcategories id="5"}" parse="inward"}

For now, this only gets the immediate children. If you have a third level, they won’t be displayed. If anyone needs that functionality, let me know. It shouldn’t be too hard to add.

Changelog 1.0.2 - Changed the plugin name to “VZ Subcategories” so as not to conflict with the pre-existing Child Categories plugin. 1.0.3 - Respect the category sort order.

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi,

You are unlucky: Subcategories plugin also exists already. You can find it here.

       
EliVZ's avatar
EliVZ
37 posts
16 years ago
EliVZ's avatar EliVZ

Damn, I even searched and that one didn’t come up for some reason. I’m going with “VZ Subcategories”. Namespacing FTW.

       
NKT com's avatar
NKT com
124 posts
16 years ago
NKT com's avatar NKT com

Would it be possible to just set a category group id and get a list of all the top level categories. Sorted by their custom sort method.

       
NKT com's avatar
NKT com
124 posts
16 years ago
NKT com's avatar NKT com

Ok i’ve modded the plugin to do what i want by changing parent_id to group_id. Yay! I’m a PHP newb, does anyone know how i would sort the results by their category order?

       
EliVZ's avatar
EliVZ
37 posts
16 years ago
EliVZ's avatar EliVZ

Hey, NKT,

Glad you figured out the first part of your question. To sort them, just add “ORDER BY cat_order” to the end of the query statement. So all together that line would be:

$results = $DB->query("SELECT cat_id FROM exp_categories WHERE group_id = '".$parent_id."' ORDER BY cat_order");

I’m not sure if group listing function really fits into this plugin at this point, but I am going to update it to sort, which it really should have been doing all along. Thanks for the idea!

-Eli

       
awa's avatar
awa
77 posts
15 years ago
awa's avatar awa

Hi Eli, found this cool plugin while searching for a solution. But I have EE2 :-( Do you have plans, to update this plugin for EE2?

Cheers awa

       
EliVZ's avatar
EliVZ
37 posts
15 years ago
EliVZ's avatar EliVZ

I would love to port it to EE2, but I’m not likely to have time in the next few months. If someone else wants to go for it, you have my blessing. Otherwise, I’ll get to it as soon as I can.

       
awa's avatar
awa
77 posts
15 years ago
awa's avatar awa

Too bad, but thanks for the reply. 😉 awa

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.