1 of 6
1
Plugin: Child Categories
Posted: 08 August 2008 04:27 AM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  285
Joined  02-02-2007

The purpose of this plugin is to display a list of subcategories for a given category.

PARAMETERS (All optional):

  1) parent - specify parent category id number.
  You can stack parent categories using pipe character e.g. parent=“3|16|28”.
  2) sibling - specify child category id number
  (plugin will find parent category and other child categories).
  Either “parent” or “sibling” parameter MUST BE defined.
  3) weblog - specify weblog name. Pipeline character and “not” are supported.
  4) site - specify site id number.
  5) child_categories_sort_by - specify sort order
  of child categories. This parameter accepts three values: “name” (child
  categories will be sorted by name), “id” (child categories will be sorted
  by id number), and “custom” (child categories will be sorted using custom order
  as defined in control panel). Default value is “name”.
  6) child_categories_sort_direction - This parameter accepts two values: “asc” and “desc”. Default value is “asc”.
  7) show_empty - specify if child categories having no
  entries should be displayed or not. This parameter accepts two values: “yes” and “no”.
  Default value is “no”.
  8) entries_sort_by - specify sort order of entries.
  This parameter accepts two values: “title” and “date”. Default value is “date”.
  9) entries_sort_direction - specify sort direction
  of entries. This parameter accepts two values: “asc” and “desc”.
  Default value is “desc”.
  10) entries_limit - specify how many entries posted into
  child category should be displayed. This parameter accepts as its value an integer
  or “none”. Default value is “10”. Value “none” means that all entries will be
  displayed.
  11) date_format - specify PHP date format string
  (Not ExpressionEngine’s date format string!). Default value is “Y-m-d”.
12) show_expired - If the value is “yes”, expired entries will be counted; if the value is “no”, expired entries will not be counted. Default is “yes”.
  13) status - specify status of entries. “not” and pipe characters are supported.
  14) 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. Set this parameter to “alert” for development, and to “silence” - for deployment. Default is “silence”.

VARIABLE PAIRS:
 
  1) {parent_category_start}{parent_category_end} - Allows you to specify portion of
  code which will be iterated as many times as there are parent categories.
  Single variables available for use inside this variable pair:

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


  2) {child_category_start}{child_category_end} - Allows you to specify portion of
  code which will be iterated as many times as there are child categories.
  Single variables available for use inside this variable pair:

{parent_category_id}
{parent_category_name}
{parent_category_url_title}
{parent_category_description}
{parent_category_image}
{parent_category_children_count}
{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.
{entries_total}


  3) {entries_start}{entries_end} - Use it to specify portion of
  code which will be iterated as many times as there are entries posted into child
  category. Single variables available for use inside this variable pair:

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


4) {entries_wrapper_top_start}{entries_wrapper_top_end} - specify top part of the code with which you want to wrap output of {entries_start}{entries_end} variable pair.
5) {entries_wrapper_bottom_start}{entries_wrapper_bottom_end} - specify bottom part of the code with which you want to wrap output of {entries_start}{entries_end} variable pair.
6) {child_wrapper_bottom_start}{child_wrapper_bottom_end} - specify bottom part of the code with which you want to wrap all data of child category.
7) {parent_wrapper_bottom_start}{parent_wrapper_bottom_end} - specify bottom part of the code with which you want to wrap all data of parent category.

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}</a> Weblog: {weblog_name}, posted: {entry_date}</li>
  
{entries_end}

{entries_wrapper_bottom_start}
</ul>{entries_wrapper_bottom_end}

  {
/exp:child_categories}

File Attachments
pi.child_categories_v1.5.zip  (File Size: 7KB - Downloads: 4)
 Signature 

Full list of plugins here

Child Categories
Browser Sniff
Category Id
Entries List

Profile
 
 
Posted: 08 August 2008 07:15 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  307
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 10:23 AM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  72
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 11:12 AM   [ Ignore ]   [ # 3 ]  
Grad Student
Avatar
Rank
Total Posts:  64
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 | The Visual Chefs | EECoder

Profile
 
 
Posted: 15 August 2008 12:20 AM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  285
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 plugins here

Child Categories
Browser Sniff
Category Id
Entries List

Profile
 
 
Posted: 15 August 2008 03:17 AM   [ Ignore ]   [ # 5 ]  
Grad Student
Rank
Total Posts:  72
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 05:27 AM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  285
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 plugins here

Child Categories
Browser Sniff
Category Id
Entries List

Profile
 
 
Posted: 15 August 2008 05:42 AM   [ Ignore ]   [ # 7 ]  
Grad Student
Rank
Total Posts:  72
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 05:55 AM   [ Ignore ]   [ # 8 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  285
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 plugins here

Child Categories
Browser Sniff
Category Id
Entries List

Profile
 
 
Posted: 15 August 2008 06:05 AM   [ Ignore ]   [ # 9 ]  
Grad Student
Rank
Total Posts:  72
Joined  07-10-2008

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

Profile
 
 
Posted: 15 August 2008 07:56 AM   [ Ignore ]   [ # 10 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  285
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 plugins here

Child Categories
Browser Sniff
Category Id
Entries List

Profile
 
 
Posted: 15 August 2008 08:09 AM   [ Ignore ]   [ # 11 ]  
Grad Student
Rank
Total Posts:  72
Joined  07-10-2008

That is working perfect! Thank you, great work!

Profile
 
 
Posted: 21 August 2008 09:33 AM   [ Ignore ]   [ # 12 ]  
Grad Student
Avatar
Rank
Total Posts:  56
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 06:18 AM   [ Ignore ]   [ # 13 ]  
Grad Student
Avatar
Rank
Total Posts:  56
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”}                   

<h2>child ID: {child_category_id}</h2>
<p>child Name: {child_category_name} </p>
<p>child Title: {child_category_url_title} </p>
<p>child Image: {child_cat_image} </p>
<p>child Description: {child_category_description}</p>

{/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 07:08 AM   [ Ignore ]   [ # 14 ]  
Grad Student
Rank
Total Posts:  96
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 09:01 AM   [ Ignore ]   [ # 15 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  285
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 plugins here

Child Categories
Browser Sniff
Category Id
Entries List

Profile
 
 
Posted: 22 August 2008 09:24 AM   [ Ignore ]   [ # 16 ]  
Grad Student
Avatar
Rank
Total Posts:  56
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 09:59 AM   [ Ignore ]   [ # 17 ]  
Grad Student
Rank
Total Posts:  96
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 10:27 AM   [ Ignore ]   [ # 18 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  285
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 plugins here

Child Categories
Browser Sniff
Category Id
Entries List

Profile
 
 
   
1 of 6
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64938 Total Logged-in Users: 55
Total Topics: 81910 Total Anonymous Users: 54
Total Replies: 440320 Total Guests: 296
Total Posts: 522230    
Members ( View Memberlist )