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
16 years ago
Laisvunas's avatar Laisvunas

Hi Jerry,

Child Categories plugin does not support functionality you need.

But it seems that you can achieve it by combining Child Categories plugin with Subcategories plugin which has {subcategories_count} variable.

The code would be as follows (enter correct weblog_id as the value of the “weblogs” parameter of exp:subcategories tag):

{exp:category_id category_group="3" category_url_title="{segment_3}" parse="inward"}
{exp:subcategories root_node="{category_id}" weblogs="22" parse="inward"}
{if "{subcategories_count}"==0}
Sorry there are no children categories
{/if}
{/exp:subcategories}

    {exp:child_categories weblog="music" parent="{category_id}" parse="inward" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes"}
        {child_category_start}
             <a href="/template_group/template/{child_category_url_title}/">{child_category_name}</a>
        {child_category_end}
  {/exp:child_categories}
{/exp:category_id}
       
webprouk's avatar
webprouk
69 posts
16 years ago
webprouk's avatar webprouk

Hello

I think I have a similar problem, I need to create a menu where I display categories, subcategories and entries, but some of my categories do not have subcategories, and using your plugin I cannot display entries unless they are under a subcategory. Do I have to combine the Subcategories plugin with yours or is there a simpler way to achieve this?

Thanks

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi webprouk,

It seems that you not need to use either Child Categories plugin or Subcategories plugin. You can achieve what you need using exp://weblog:category_archive tag.

       
webprouk's avatar
webprouk
69 posts
16 years ago
webprouk's avatar webprouk

I am afraid that the category_archive tag does not work for me, as the menu is collapsing using javascript and I need to be able to format the lists, the category_archive tag outputs nested lists but I need to give them an id.

I have this part working using a category_archive tag that displays parents only and then a weblog entries tag to display the items.

I want to be able to display subcategories if there are any and their articles, or just the articles if there are no subcategories.

Example:

Category 1 Article 1 Article 2 Category 2 Subcategory 1 Article 3 Subcategory 2 Article 4 Category 3 Article 5

Adding the facility to display articles under categories (where there are no subcategories) to the child categories plugin would sort my problem :D

       
Mary FS's avatar
Mary FS
22 posts
16 years ago
Mary FS's avatar Mary FS

This plug in is GREAT!

I’d like to second the request for a ‘status’ parameter to be able to filter entries. Currently even closed entries are being displayed, or am I missing something?

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

@webprouk If the category_archive tag does not work then I do not know what would. The functionality you need I do not plan to include into Child categories plugin because its purpose is different - to display child categories for certain parent category or categories. It seems that you should code your own plugin, perhaps forking Child Categories or Subcategories plugin.

@Mary FS As I said in previous post, “status” parameter is under consideration for the next release.

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi all,

I have released version 1.5 of Child Categories plugin.

In this release:

1) “status” parameter was added. It allows you to specify status of entries. You can stack statuses using pipe character to get entries having any of those statuses, e.g. status=”open|draft”. Or use “not” (with a space after it) to exclude statuses, e.g. status=”not submitted|processing|closed”.

2) “show_expired” parameter was added. It allows you to specify if you wish expired entries to be displayed. If the value is “yes”, expired entries will be displayed; if the value is “no”, expired entries will not be displayed. Default value is “yes”.

3) {parent_category_children_count} variable was added. It outputs number of child categories for parent category. The result depends on the value of “show_empty” parameter. If this parameter has the value “yes” then all child categories will be counted; if this parameter has the value “no” then only those child categories will be counted into which at least one entry was posted.

4) two new variable pairs - {child_wrapper_bottom_start}{child_wrapper_bottom_end} and {parent_wrapper_bottom_start}{parent_wrapper_bottom_end} - was added. {child_wrapper_bottom_start}{child_wrapper_bottom_end} variable pair allows you to specify bottom part of the code with which you want to wrap all data of child category. {parent_wrapper_bottom_start}{parent_wrapper_bottom_end} variable pair allows you to specify bottom part of the code with which you want to wrap all data of parent category. Using these variable pars together with {entries_wrapper_top_start}{entries_wrapper_top_end} variable pair you can write the code such as this:

{exp:child_categories parent="179" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="no" entries_sort_by="date" entries_sort_direction="asc" entries_limit="5"}

{parent_category_start}
<ul><li><!-- Opening part of the code which wrap parent category -->
Parent category: {parent_category_name}, child categories: {parent_category_children_count}
{parent_category_end}

{child_category_start}
<ul><li><!-- Opening part of the code which wrap child category -->
Category: {child_category_name}, {entries_total} entries
{child_category_end}

{entries_wrapper_top_start}
<ul><!-- Opening part of the code which wraps entries -->
{entries_wrapper_top_end}

{entries_start}
<li>Entry: {count}. {title}</li>
{entries_end}

{entries_wrapper_bottom_start}
</ul><!-- Closing part of the code which wraps entries -->
{entries_wrapper_bottom_end}

{child_wrapper_bottom_start}
</li></ul><!-- Closing part of the code which wrap child category -->
{child_wrapper_bottom_end}

{parent_wrapper_bottom_start}
</li></ul><!-- Closing part of the code which wrap parent category -->
{parent_wrapper_bottom_end}

{/exp:child_categories}
       
hothousegraphix's avatar
hothousegraphix
851 posts
16 years ago
hothousegraphix's avatar hothousegraphix

For give me if I’ve missed this. But, i’m curious, if I’m using a scheme the employs a Parent Category/Subcategory arrangement and apply a sub-category to an entry is there a way in my “Search Results” to use this plugin to display only the parent category of the entry in question?

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi hothousegraphix,

if I’m using a scheme the employs a Parent Category/Subcategory arrangement and apply a sub-category to an entry is there a way in my “Search Results” to use this plugin to display only the parent category of the entry in question?

Perhaps there is such possibility - if parse=”inward” parameter will work for exp:search:search_results tag. The code would be as here:

{exp:search:search_results parse="inward"}

<tr>
<td>{title}</td>
<td>{comment_total}</td>
<td>{categories}
{exp:child_categories sibling="{category_id}" site="1"}
{parent_category_start}{parent_category_name}{parent_category_end}
{/exp:child_categories}
{/categories}</td>
</tr>

{/exp:search:search_results}
       
hothousegraphix's avatar
hothousegraphix
851 posts
16 years ago
hothousegraphix's avatar hothousegraphix

Thank you very much for your response. This does seem to work; and regardless of the use of the parse=”inward” parameter.

Conversely, I’d also like to know if (as with this solution) it’s possible to display the sub-category (and only the that) applied to an entry in the search results.

I have tried to get the plugin to return this result to no avail.

The closest I’ve come (and it’s not that close) is

{categories}
{exp:child_categories parent="{category_id}" site="1"}
{child_category_start}{child_category_name}{child_category_end}
{/exp:child_categories}
{/categories}

which produces a listing of all subcategories that fall under the Main Category the entry has been applied to.

I’m interested in only showing the single sub-category applied the entries returned.

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi hothousegraphix,

To display only child category try this code:

{exp:search:search_results parse="inward"}

<tr>
<td>{title}</td>
<td>{comment_total}</td>
<td>
{categories}
{exp:query sql="SELECT parent_id, cat_id FROM exp_categories WHERE exp_categories.cat_id='{category_id}' AND site_id='1' LIMIT 0, 1"}

{if "{parent_id}"==""}{category_name}{/if}

{/exp:query}
{/categories}


</td>
</tr>

{/exp:search:search_results}

Not sure some parse order issue will not interfere, but it may work.

       
hothousegraphix's avatar
hothousegraphix
851 posts
16 years ago
hothousegraphix's avatar hothousegraphix

Again, thanks.

This seems to be returning both the parent and the child category.

I do appreciate you passing on the query. I had thought the plugin might be able to handle this.

I’m assuming that the LIMIT parameter of 0,1 is supposed to ensure that the first value returned is not displayed.

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

Hi again here!

I have another question about your great plugin:

{exp:child_categories sibling="7" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" entries_sort_by="date" entries_sort_direction="asc"}
                      
{child_category_start}                   
<h1>{child_category_name}</h1>
{child_category_description}        
{child_category_end}                   
                                           
{/exp:child_categories}

I would expect that this would show the name and description of my child category number 7. This does not work, it keeps showing all child categories that are in the same parent category as child catagory number 7…

Am I looking at this the wrong way?

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi goodbytes,

I would expect that this would show the name and description of my child category number 7.

That’s not correct. “sibling” parameter is used in cases when you do not know parent category id number. “sibling” parameter’s value is used to find parent category id number and when this id number is found, the plugin displays ALL parent category’s children.

If you need to display name and description of certain category you should rather use weblog categories tag.

The code would be as here:

{exp:weblog:categories weblog="weblog_name" show="7"}

{category_name}

{category_description}



{/exp:weblog:categories}
       
hothousegraphix's avatar
hothousegraphix
851 posts
16 years ago
hothousegraphix's avatar hothousegraphix

Hello, I appreciate the guidance thus far. I’m still struggling to get this to do what I want.

Is there a way, on a per entry basis, to display the “child_category_name” applied to the entry.

I am able to produce my list of sub-categories with the plugin tags -

{exp:child_categories parent="{category_id}"}
{child_category_start}{child_category_name}{child_category_end}
{/exp:child_categories}

And the query provided returns the entry’s parent and child -

{categories}
{exp:query sql="SELECT parent_id, cat_id FROM exp_categories WHERE exp_categories.cat_id='{category_id}' AND site_id='1' LIMIT 0, 1"}

{if "{parent_id}"==""}{category_name}{/if}
//changed the if statement to "{parent_id}'=='" w/single quotes wrapping the ==

{/exp:query}
{/categories}

Have I missed something that I need to plug into the query? I’m not too sure what I need to do.

       
First 5 6 7 8 9 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.