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.
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.
@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.
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.
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.
@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?
@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.
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:
List of Entries in this Category
or, for example:
Apple Pies Cherry Pies Banana 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
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.