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: Child Categories

Development and Programming

Laisvunas's avatar
Laisvunas
879 posts
about 17 years ago
Laisvunas's avatar Laisvunas

The attached add-on files may be out of date. Please visit Devot-ee for the latest versions.

Displays subcategories.

PARAMETERS (All optional):

1) parent - parent category id. Pipe is supported e.g. parent=”3|16|28”. 2) sibling - child category id (plugin will find parent). 3) category_group - category group id or name (highest level categories of that category group will be treated by plugin as parent categories). Either “parent” or “sibling” or “category_group” MUST BE defined. 4) weblog - weblog name. Pipe and “not” supported. 5) site 6) parent_categories_sort_by - for use with “category_group” parameter. Values: “name”, “id” and “custom”. 7) parent_categories_sort_direction - used with “category_group” parameter. Accepts values “asc” and “desc”. Default “asc”. 8) child_categories_sort_by - values: “name”, “id” and “custom” (children will be sorted using custom order as defined in control panel). Default “name”. 9) child_categories_sort_direction - values: “asc” and “desc”. Default is “asc”. 10) show_empty - specify if child categories having no entries should be displayed. Accepts values “yes” and “no”. Default “no”. 11) entries_sort_by - values: “title” and “date”. Default “date”. 12) entries_sort_direction - values: “asc” and “desc”. Default is “desc”. 13) entries_limit - how many entries posted into child category should be displayed. Accepts as its value an integer or “none”. Default is “10”. Value “none” means that all entries will be displayed. 14) date_format - PHP date format string (Not ExpressionEngine’s date format string!). Default is “Y-m-d”. 15) show_expired - values: “yes” and “no”. Default “yes”. 16) status - status of entries. “not” and pipe supported. 17) invalid_input - If the value is “alert”, then in cases when some parameter’s value is invalid plugin exits and PHP alert is being shown; if the value is “silence”, then such in cases plugin finishes its work without any alert being shown. Default is “silence”. 18) custom_field_name - used with “custom_field_value” parameter to display child categories with specific category custom field equal, not equal or like to specific value. 19) custom_field_value 20) custom_field - values: “include”, “exclude”, “like”. Used to display child categories with specific category custom field equal not equal or like to specific value. Default is “include”.

VARIABLE PAIRS:

1) {parent_category_start}{parent_category_end} - wraps code which will be iterated for each parent. Single vars:

{parent_category_id}
{parent_category_name}
{parent_category_url_title}
{parent_category_description}
{parent_category_image}
{parent_category_children_count}
{parent_category_count}
{parent_category_total}

2) {child_category_start}{child_category_end} - wraps code which will be iterated for each child. Single vars:

{parent_category_id}
{parent_category_name}
{parent_category_url_title}
{parent_category_description}
{parent_category_image}
{parent_category_children_count}
{parent_category_count}
{parent_category_total}
{child_category_id}
{child_category_name}
{child_category_url_title}
{child_category_description}
{child_category_image}
{child_category_order_num} - outputs number used for custom ordering of categories.
{child_category_count} 
{entries_total}

3) {entries_start}{entries_end} - wraps code which will be iterated for each entry posted into child category. Single vars:

{parent_category_id}
{parent_category_name}
{parent_category_url_title}
{parent_category_description}
{parent_category_image}
{parent_category_children_count}
{parent_category_count}
{parent_category_total}
{child_category_id}
{child_category_name}
{child_category_url_title}
{child_category_description}
{child_category_image}
{child_category_order_num}
{child_category_count}
{entries_total}
{weblog_name}
{weblog_short_name}
{weblog_url}
{title}
{url_title}
{entry_date}
{entry_id}
{count}

4) {entries_wrapper_top_start}{entries_wrapper_top_end} - top part of the code with which you may want to wrap output of {entries_start}{entries_end} variable pair. Single vars:

{entries_total}
{child_category_id}

5) {entries_wrapper_bottom_start}{entries_wrapper_bottom_end} - bottom part of the code with which you may want to wrap output of {entries_start}{entries_end} variable pair. Single vars:

{entries_total}
{child_category_id}

6) {child_wrapper_bottom_start}{child_wrapper_bottom_end} - bottom part of the code with which you may want to wrap all data of child category. Single vars:

{entries_total}
{child_category_id}

7) {parent_wrapper_bottom_start}{parent_wrapper_bottom_end} - bottom part of the code with which you may want to wrap all data of parent category. Single vars:

{parent_category_children_count}
{parent_category_id}

The tag {exp:child_categories} MUST contain at least one variable pair out of {parent_category_start}{parent_category_end}, {child_category_start}{child_category_end} and {entries_start}{entries_end} variable pairs and each single variable MUST BE inside relevant variable pair.

EXAMPLE OF USAGE:

{exp:child_categories parent="18|29" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" entries_sort_by="date" entries_sort_direction="asc" entries_limit="3" site="1"}
{parent_category_start}
<h1><a href="http://{homepage}/category/{parent_category_url_title}/">{parent_category_name}</a></h1>
{parent_category_end}
{child_category_start}
<h2><a href="http://{homepage}/category/{child_category_url_title}/">{child_category_name}</a></h2>
Total entries: {entries_total}

{child_category_end}
{entries_wrapper_top_start}<ul>{entries_wrapper_top_end}
{entries_start}
<li><a href="http://{weblog_url}{url_title}/">{title}</a> Weblog: {weblog_name}, posted: {entry_date}</li>
{entries_end}
{entries_wrapper_bottom_start}</ul>{entries_wrapper_bottom_end}
{/exp:child_categories}
       
AJP's avatar
AJP
311 posts
about 17 years ago
AJP's avatar AJP

Holy cow, this might be just what I’m looking for to get rid of all kinds of query module usage.

Thanks!

       
combinedmedia's avatar
combinedmedia
79 posts
about 17 years ago
combinedmedia's avatar combinedmedia

Great ! Thank you. Its working great. Just have two questions:

  1. I have 2 weblogs using the same category_group and want to display entries only from 1 weblog….is this possible to define weblog?
  2. Is this possible to display all categories and subcategories without defining parent=”18|29” but defining category_group_id so it would display all categories and subcategories within its category_group? That would work great as after adding a new category it will work without adding category_id to parent parameter

Great work! Tank you

       
fostermade's avatar
fostermade
97 posts
about 17 years ago
fostermade's avatar fostermade

Great. I’ll have to check this out. I’ve been hacking subcategories to suit my purposes for a long time.

Thanks for your hard work!

-Shawn

       
Laisvunas's avatar
Laisvunas
879 posts
about 17 years ago
Laisvunas's avatar Laisvunas

Hi,

I have 2 weblogs using the same category_group and want to display entries only from 1 weblog….is this possible to define weblog?

Currently it is not possible, but it seems that to add “weblog” parameter should not be complicated. I will consider this suggestion when releasing a new version.

Is this possible to display all categories and subcategories without defining parent=”18|29” but defining category_group_id so it would display all categories and subcategories within its category_group? That would work great as after adding a new category it will work without adding category_id to parent parameter

Have you considered exp:weblog:categories tag? This tag has “category_group” parameter and “style” parameter which accepts value “nested”. It seems that exp:weblog:categories tag can display all categories and subcategories within its category_group - exactly as you want.

       
combinedmedia's avatar
combinedmedia
79 posts
about 17 years ago
combinedmedia's avatar combinedmedia

Hi Thank you, Im now using exp:weblog:categories tag but im not getting exacly the results I want. I need to display all categories and subcategories within categories and as well titles of entries from these subcategories

So my code looks like this

{exp:weblog:categories category_group="2"  weblog="server_product" }      
 <li><a href="http://{site_url}index.php/servers/category/C{category_id}">{category_name}</a>


{exp:weblog:entries weblog="server_product" category_id="{category_id}"}
{title}

{/exp:weblog:entries}

</li>
{/exp:weblog:categories}

Its displaying properly all categories and subcategories, but its displaying all entries under every category and subcategory….like:

cat1
entry1
entry2
entry3

sub1
entry1
entry2
entry3

sub2
entry1
entry2
entry3

cat2
entry1
entry2
entry3

sub21
entry1
entry2
entry3

sub22
entry1
entry2
entry3

where its should be:

cat1
sub1
entry1
entry2

cat2
sub21
entry3

Do you have maybe idea how to fix it? Thank you

       
Laisvunas's avatar
Laisvunas
879 posts
about 17 years ago
Laisvunas's avatar Laisvunas

Hi combinedmedia,

Try the following code:

{exp:weblog:categories category_group="2"  weblog="server_product"}
{exp:child_categories parent="{category_id}" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="no" entries_sort_by="date" entries_sort_direction="asc" entries_limit="5" site="1"}

{parent_category_start}
<a href="http://{site_url}index.php/servers/category/C{parent_category_id}">{parent_category_name}</a>

{parent_category_end}

{child_category_start}
<a href="http://{site_url}index.php/servers/category/C{child_category_id}">{child_category_name}</a>

{child_category_end}

{entries_start}
<a href="http://{site_url}index.php/servers/category/C{child_category_id}/{url_title}/">{title}</a>

{entries_end}


{/exp:child_categories}
{/exp:weblog:categories}

Not sure it will work, but it seems worth to try.

       
combinedmedia's avatar
combinedmedia
79 posts
about 17 years ago
combinedmedia's avatar combinedmedia

Hi Thank you, its working but unfortunatelly it still displays entries from 2 weblogs, like there is no parametr weblog. I was trying a lot of combinations and nothing is working. I will probably create a new category group and connect them to my weblog, so it will display properly. Thank you very much for help!

       
Laisvunas's avatar
Laisvunas
879 posts
about 17 years ago
Laisvunas's avatar Laisvunas

Hi,

If it is not an emergency situation, and you can wait a day or a couple of days, I will add “weblog” parameter to Child Categories plugin.

       
combinedmedia's avatar
combinedmedia
79 posts
about 17 years ago
combinedmedia's avatar combinedmedia

Its not emergency, so great I will wait. Thanks so much!

       
Laisvunas's avatar
Laisvunas
879 posts
about 17 years ago
Laisvunas's avatar Laisvunas

Just updated the plugin to version 1.1.

In version 1.1 two new things are added:

1) parameter “weblog”: it allows you to specify weblog name. You can use the pipe character to get entries from any of those weblogs, e.g. weblog=”weblog1|weblog2|weblog3”. Or you can add the word “not” (with a space after it) to exclude weblogs, e.g. weblog=”not weblog1|weblog2|weblog3”;

2) variable {weblog_short_name}: it outputs short name of the weblog. If you wish to output full name, use variable {weblog_name}.

If you use parameter “weblog”, then the search will go only through the specified weblogs. That means that the output of {entries_total} variable will be accordingly affected: entries which are posted into weblogs not included by “weblog” parameter will not be counted.

       
combinedmedia's avatar
combinedmedia
79 posts
about 17 years ago
combinedmedia's avatar combinedmedia

That is working perfect! Thank you, great work!

       
Paul Cripps (Nine Four)'s avatar
Paul Cripps (Nine Four)
104 posts
16 years ago
Paul Cripps (Nine Four)'s avatar Paul Cripps (Nine Four)

@Laisvunas, what a great plugin, been after something like this for too long!!

Is it possible to also get:

{category_image} {category_description}

as you can with exp:weblog:categories?

If not could you add this for us?

       
Paul Cripps (Nine Four)'s avatar
Paul Cripps (Nine Four)
104 posts
16 years ago
Paul Cripps (Nine Four)'s avatar Paul Cripps (Nine Four)

Laisvunas following my last post this is what I need to achive, the problem is if the client adds a catagory the we’ll need to amend this code as the IDs are hard coded so it aint great:

{exp:query sql = ” SELECT cat_id AS child_category_id, cat_name AS child_category_name, cat_url_title AS child_category_url_title, cat_description AS child_category_description, cat_image AS child_cat_image,
cat_order AS child_cat_order
FROM exp_categories WHERE parent_id = ‘11’ ORDER BY cat_order”}

child ID: {child_category_id}

child Name: {child_category_name} child Title: {child_category_url_title} child Image: {child_cat_image} child Description: {child_category_description}

{/exp:query}

If anyone has a better idea how to achieve this please let us know, the worknig example can be seen here http://probel.previewurl.net/ click on the left nav to get a pop up whic will display child catagories.

       
goodbytes's avatar
goodbytes
49 posts
16 years ago
goodbytes's avatar goodbytes

Good work!

My only question is: can I use custom fields in the outputted results?

Right now it’s outputting {title}, but I’d like to include some of my weblog custom fields in the results. Once I get that up and running, my goal of this week has been completed 😊

thanks already for this great plugin!

UPDATE:

I managed to get really close to my goal, with following code:

{exp:child_categories parent="6" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" entries_sort_by="date" entries_sort_direction="asc"}
{parent_category_start}

{parent_category_end}


{child_category_start}
        <h2>{child_category_name}</h2>

{exp:weblog:entries weblog="menuinbeeld" dynamic="off" category="9"}
            <div class="menuitem">
                  <div class="menutitle">{title}</div>
                  <div class="menupicture">{menu_picture}</div>
                  <div class="menudesc">{menu_description}</div>
                  <div class="menuprice">{menu_price} €</div>
            </div>  
{/exp:weblog:entries}            
            
{child_category_end}


{entries_start}


{entries_end}



{/exp:child_categories}

Now you can see I hard-coded the category to “9”. This however, should be dynamically changed to {child_category_id} but just replacing the “9” with {child_category_id} does not work.

I also tried php but it didn’t work. Does anyone have an idea on how to solve this, I bet this will be useful for many people out there trying to do the same thing.

UPDATE2:

the following looks logic, but doesn’t work either :(

{child_category_start}
        <h2>{child_category_name}</h2>
                       
{assign_variable:jorre="{child_category_id}"}

{exp:weblog:entries weblog="menuinbeeld" dynamic="off" category="{jorre}"}
            <div class="menuitem">
                  <div class="menutitle">{title}</div>
                  <div class="menupicture">{menu_picture}</div>
                  <div class="menudesc">{menu_description}</div>
                  <div class="menuprice">{menu_price} €</div>
            </div>  
{/exp:weblog:entries}            
            
{child_category_end}
       
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.