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

New "Subcategories" plugin available.

Development and Programming

MF's avatar
MF
15 posts
19 years ago
MF's avatar MF

I’ve written an EE plugin that will let you show a list of subcategories for a given category. I call it the “Subcategories” plugin. It’s attached to this post as “pi.subcategories.txt”. To use the attachment (save it into your plugin folder and) rename it to pi.subcategories.php.

Please try it out and give me your feedback about bugs etc. I plan to add the final version to the ExpressionEngine’s list of plugins for EE if you like. Thanks.

       
Sue Crocker's avatar
Sue Crocker
26,054 posts
19 years ago
Sue Crocker's avatar Sue Crocker

Since I’m assuming you’re going to be using this for breadcrumbs of some sort… there isn’t anything that can be displayed if there are no results.

Other than that, it worked just fine!

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
19 years ago
Lisa Wess's avatar Lisa Wess

MF, great plugin - I know how many times this has come up. 😉 One thing I’d suggest, if it’s not hard to add - adding the category description, and the category image as variables. I only had a quick scan through the docs but didn’t see those there.

       
Chris Curtis's avatar
Chris Curtis
17 posts
19 years ago
Chris Curtis's avatar Chris Curtis

The parameter for setting the “order” of the categories doesn’t seem to have an option for respecting the custom order that someone may have used under ‘Admin > Category Management’. The custom order could be different than both the alphabetical order and the order of category IDs.

       
MF's avatar
MF
15 posts
19 years ago
MF's avatar MF

@Sue

You’re right. If a category doesn’t have any subcategories, nothing will be shown. That’s intentional.

@Lisa

I’ve added both variables {category_description} and {category_image}.

@Chris

I’ve added the value “custom_order” to the “sort_by” parameter. It will let you sort the subcategories by the same custom order you chose in the Admin section.

See the new attachment for this new version.

Thanks for all your feedback. Don’t hesitate to add more to it.

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
19 years ago
Lisa Wess's avatar Lisa Wess

You rock. I have to write a paper tonight but I’ll be playing with this over the weekend for sure. Thanks, MF =)

       
Joelle's avatar
Joelle
272 posts
19 years ago
Joelle's avatar Joelle

This is definitely intriguing. I’ll have to give it a try! Thanks. 😊

       
MF's avatar
MF
15 posts
19 years ago
MF's avatar MF

I�ve written an EE plugin that will let you show all ancestor categories of a given category. I call it the “Breadcrumb” plugin.

Note:

This plugin and the “Breadcrumb” Plugin are a pair.

The “breadcumb” Plugin will show the ancestor categories of a category and the “Subcategories” plugin will show the children categories of a category.

       
Tim Griffiths's avatar
Tim Griffiths
36 posts
19 years ago
Tim Griffiths's avatar Tim Griffiths

I for one will find both of these plugins very useful as my work project involves publishing info in much the same manner as a book, where the order of the entries needs to be by category and sub-category (chapter and sub-chapter).

I can’t tell from the docs and don’t have time to test right now, but can you tell me, could I embed a weblog entries tag pair inside the sub cat plugin tags and use the category_id output to give me a correctly ordered list of entries?

something like

{exp:subcategories sort_by="category_order"}
{exp:weblog:entries category="{category_id}"}
content...
{/exp:weblog:entries}
{/exp:subcategories}

That is, ordered according to category rather than title or date. In this situation, the order of entries is crucial. At the moment I do this with php but it is a bit of a hack (especially given my lack of php knowledge).

I’m not sure if you have even considered the possibilty of embedding other tags, but I can see a couple of problems trying to embed weblog entries tags. First, if there are no results, no entries will be shown for those bottom level categories. Second, your plugins and the weblog entries tags share some variable names. This might cause some conflicts if someone (eg: me) is foolish enough to try embedding.

Maybe consider an {if no_results} conditional?

Anyway, thanks for your hard work. I’ll definitely be giving both of these a try next week.

       
MF's avatar
MF
15 posts
19 years ago
MF's avatar MF

@Tim

a) You’re right, I had not thought of embedding other plugin/module tags in these tags. I’m not sure what it would take to make this work. Maybe EE automatically recognizes these tags within plugins. Maybe some Pro’s can share their insights regarding this.

But if it works I would think that you could order the outcome the way you want.

You/I might try it out and see what the outcome is.

b) Regarding name conflicts, I would think that that is not a problem, since parameters and variables exist within the scope/context of their plugin/module tags. But I don’t know for sure. Maybe some Pro’s can share their insights regarding this too.

You/I might try it out and see what the outcome is.

c) Regarding the {if no_results} tag. How do you want this to work? Can you tell me more?

       
MF's avatar
MF
15 posts
19 years ago
MF's avatar MF

@Tim

Currently you could use the {if entries_count == 0} tag to check if there are no entries assigned to a category. Would this help?

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
19 years ago
Lisa Wess's avatar Lisa Wess

Variables matter. I know that Yoshi ran into this with the linklist module a few times and had to rename things like the url and the {title} to be unique. It happened with the magpie plugin, too, again with {title}.

       
Tim Griffiths's avatar
Tim Griffiths
36 posts
19 years ago
Tim Griffiths's avatar Tim Griffiths
@Tim Currently you could use the {if entries_count == 0} tag to check if there are no entries assigned to a category. Would this help?

No, I mean if there are no sub-categories, provide a means to display something. There is an {if no_results} variable pair for the weblog entries tag. Maybe you could look at that. Don’t get me wrong, I’m really looking forward to testing this plugin, I’m just considering some problems I might come across in using it in my particular application.

       
MF's avatar
MF
15 posts
19 years ago
MF's avatar MF

@LisaJill

Good to know. I don’t know how I want to address that…

@Tim

Thanks for explaining 😊. You’re right this would be a helpful addition. I will add it soon.

@Sue

Now I know that you meant what Tim suggested 😊 .

       
livenomadic's avatar
livenomadic
6 posts
19 years ago
livenomadic's avatar livenomadic

I downloaded and installed the plugin and I made a template called “categories”, but I am new at this and am having problems.

Simply put, I want the template which shows this:

Category Title

List of Subcategories of that category

List of Entries in this Category

or, for example:

PIES

Apple Pies Cherry Pies Banana Pies

Cream Pies

10 Ways to Cut a Pie 101 Pie Making Tips 7 Great Pie Recipies

Here is an example of what I am trying to create.

Here is my template:

<pre><code>{assign_variable:master_weblog_name="tech"}

<!DOCTYPE html PUBLIC

       
1 2 3 Last

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.