1 of 21
1
Plugin: Child Categories
Posted: 08 August 2008 05:27 AM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1135
Joined  02-02-2007

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="{homepage}/category/{parent_category_url_title}/">{parent_category_name}</a></h1>
{parent_category_end}
{child_category_start}
<h2><a href="{homepage}/category/{child_category_url_title}/">{child_category_name}</a></h2>
Total entries{entries_total}<br>
{child_category_end}
{entries_wrapper_top_start}
<ul>{entries_wrapper_top_end}
{entries_start}
<li><a href="{weblog_url}{url_title}/">{title}</aWeblog{weblog_name}posted{entry_date}</li>
{entries_end}
{entries_wrapper_bottom_start}
</ul>{entries_wrapper_bottom_end}
{
/exp:child_categories} 
 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 08 August 2008 08:15 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  366
Joined  01-20-2006

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

Thanks!

 Signature 

AJ Penninga
Pretty Squares, LLC - http://www.prettysquares.com

Profile
 
 
Posted: 14 August 2008 11:23 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
RankRank
Total Posts:  124
Joined  07-10-2008

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

Profile
 
 
Posted: 14 August 2008 12:12 PM   [ Ignore ]   [ # 3 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  113
Joined  01-11-2007

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

 Signature 

Shawn Maida | EECoder | The Visual Chefs

Profile
 
 
Posted: 15 August 2008 01:20 AM   [ Ignore ]   [ # 4 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1135
Joined  02-02-2007

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.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 15 August 2008 04:17 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
RankRank
Total Posts:  124
Joined  07-10-2008

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="{site_url}index.php/servers/category/C{category_id}">{category_name}</a>
<
br />
{exp:weblog:entries weblog="server_product" category_id="{category_id}"}
{title}
<br />
{/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

Profile
 
 
Posted: 15 August 2008 06:27 AM   [ Ignore ]   [ # 6 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1135
Joined  02-02-2007

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="{site_url}index.php/servers/category/C{parent_category_id}">{parent_category_name}</a><br>
{parent_category_end}

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

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


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

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

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 15 August 2008 06:42 AM   [ Ignore ]   [ # 7 ]  
Lab Assistant
RankRank
Total Posts:  124
Joined  07-10-2008

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!

Profile
 
 
Posted: 15 August 2008 06:55 AM   [ Ignore ]   [ # 8 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1135
Joined  02-02-2007

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.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 15 August 2008 07:05 AM   [ Ignore ]   [ # 9 ]  
Lab Assistant
RankRank
Total Posts:  124
Joined  07-10-2008

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

Profile
 
 
Posted: 15 August 2008 08:56 AM   [ Ignore ]   [ # 10 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1135
Joined  02-02-2007

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.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 15 August 2008 09:09 AM   [ Ignore ]   [ # 11 ]  
Lab Assistant
RankRank
Total Posts:  124
Joined  07-10-2008

That is working perfect! Thank you, great work!

Profile
 
 
Posted: 21 August 2008 10:33 AM   [ Ignore ]   [ # 12 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  110
Joined  04-14-2006

@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?

Profile
 
 
Posted: 22 August 2008 07:18 AM   [ Ignore ]   [ # 13 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  110
Joined  04-14-2006

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.

Profile
 
 
Posted: 22 August 2008 08:08 AM   [ Ignore ]   [ # 14 ]  
Grad Student
Rank
Total Posts:  71
Joined  02-19-2007

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 smile

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} &euro;</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} &euro;</div>
            </
div>  
{/exp:weblog:entries}            
            
{child_category_end} 
Profile
 
 
Posted: 22 August 2008 10:01 AM   [ Ignore ]   [ # 15 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1135
Joined  02-02-2007

Hi guys,

Just uploaded version 1.2 of Child categories plugin. Grab it using the link in the first post in this thread.

New features added:

1) {parent_category_description} variable. It outputs description of parent category. Use this variable inside {parent_category_start}{parent_category_end}, {child_category_start}{child_category_end} and {entries_start}{entries_end} variable pairs.

2) {parent_category_image} variable. It outputs url of the image of parent category. Use this variable inside {parent_category_start}{parent_category_end}, {child_category_start}{child_category_end} and {entries_start}{entries_end} variable pairs.

3) {child_category_description} variable. It outputs description title of child category. Use this variable inside {child_category_start}{child_category_end} and {entries_start}{entries_end} variable pairs.

4) {child_category_image} variable. It outputs url of the image of child category. Use this variable inside {child_category_start}{child_category_end} and {entries_start}{entries_end} variable pairs.

5) {count} variable. It outputs order number of entry. Use this variable inside {entries_start}{entries_end} variable pair.

@ Paul Cripps

We really need to display child only catagories and to display:
{category_name}
{category_description}
{category_id}
{category_image}
{count}
{total_results}

{count} is now available for use. Concerning other variables in your list, use:
instead of {category_name} - {parent_category_name} and {child_category_name};
instead of {category_description} - {parent_category_description} and {child_category_description};
instead of {category_id} - {parent_category_id} and {child_category_id};
instead of {category_image} - {parent_category_image} and {child_category_image};
instead of {total_results} - {entries_total}.

@ goodbytes

It seems that you need to use EntryData plugin together with Child Categories plugin. Using these plugins together you should add parse=“inward” parameter to {exp:child_categories} tag.

Try this code:

{exp:child_categories parse="inward" all_other_parameters="........."}
{entries_start}
{exp
:entrydata:field field="menu_picture" weblog="{weblog_short_name}" url_title="{url_title}"}<br>
{exp:entrydata:field field="menu_description" weblog="{weblog_short_name}" url_title="{url_title}"}<br>
{exp:entrydata:field field="menu_price" weblog="{weblog_short_name}" url_title="{url_title}"}<br>
{entries_end}
{exp
:child_categories} 

 
It should work if you will not make some mistake while coding this.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 22 August 2008 10:24 AM   [ Ignore ]   [ # 16 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  110
Joined  04-14-2006

Laisvunas you are a star, I’ll give it a go now and let you know ho we go.

Profile
 
 
Posted: 22 August 2008 10:59 AM   [ Ignore ]   [ # 17 ]  
Grad Student
Rank
Total Posts:  71
Joined  02-19-2007

Thanks a lot Laisvunas!

The parse=“inward” did the job.
My only concern remaining is the parent parameter which should also be filled in dynamically…

{exp:child_categories parse=“inward” parent=“6”

do you know how I can do this?
My url looks like “food/percat/category/cold_food/”, and I need to have the parent ID dynamicallly filled in in your plugin to make it work completely…

any tips are appreciated!

Thanks again and keep up your good work

Profile
 
 
Posted: 22 August 2008 11:27 AM   [ Ignore ]   [ # 18 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1135
Joined  02-02-2007

Hi goodbytes,

My url looks like “food/percat/category/cold_food/”, and I need to have the parent ID dynamicallly filled in in your plugin to make it work completely…

“cold_food” is url_title of parent category, isn’t it? If it is a case, then you can achieve what you want using Child Categories plugin together with another my plugin,  Category Id. This plugin allows you to find category id after supplying category url_title. Do not forget to include parse=“inward” parameter into both {exp:child_categories} and {exp:category_id} tags.

The code should be approximately as follows:

{exp:category_id category_group="5" category_url_title="{segment_4}" parse="inward"}
{exp
:child_categories parent="{category_id}" parse="inward" all_other_parameters="......"}
{entries_start}
{exp
:entrydata:field field="menu_picture" weblog="{weblog_short_name}" url_title="{url_title}"}<br>
{exp:entrydata:field field="menu_description" weblog="{weblog_short_name}" url_title="{url_title}"}<br>
{exp:entrydata:field field="menu_price" weblog="{weblog_short_name}" url_title="{url_title}"}<br>
{entries_end}
{
/exp:child_categories}
{
/exp:category_id} 

Don’t be afraid if you get a sandwich made of two, three or even four nested plugins. It should work if you use parse=“inward” where needed.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
   
1 of 21
1