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 stinhambo,

If you need that parent category which has only empty children would not be displayed, then set parameter “show_empty” to “no” and use the code as follows:

{parent_category_start}
{if "{parent_category_children_count}" > "0"}
<h3><a href="">{parent_category_name} - {parent_category_children_count}</a></h3>
<div class="lessons">
    <p class="instructions">to download or view a lesson plan select from the lessons below</p>
{/if}
{parent_category_end}
       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi drpudding’

  1. I do not know why ul and li tags are displayed as html entities. You can solve rhis problenm easily by doing another find/replace. Since you already use Find and Replace Plus plugin, you will need Find and Replace plugin:
{exp:replace find="& lt ;|& gt ;" replace="<|>" multiple="yes"}
{exp:replace_plus parse="inward"}
        {exp:child_categories parse="inward" parent="{replace_area find="C"}{segment_2}{/replace_area}" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="no"}
    
        {parent_category_start}
            <h2>FAQs: {parent_category_name}</h2>
        {parent_category_end}
    
        {child_category_start}
            <h3>{child_category_name}</h3>
        {child_category_end}
    
        {entries_wrapper_top_start}<div id="faqentries">{entries_wrapper_top_end}
        {entries_start}

            <div class="question">{exp:single_field field="f_question" weblog="{my_weblog}" entry_id="{entry_id}" field_format="xhtml"}</div>
            <div class="answer">{exp:single_field field="f_answer" weblog="{my_weblog}" entry_id="{entry_id}" field_format="xhtml"}</div>
        {entries_end}
        {entries_wrapper_bottom_start}</div>{entries_wrapper_bottom_end}
        
        {/exp:child_categories}
    {/exp:replace_plus} 
{/exp:replace}
  1. If you need to display only one child category per parent, use this code
{child_category_start}
{if "{child_category_count}" == "1"}
{child_category_name}
{/if}
{child_category_end}
       
drpudding's avatar
drpudding
58 posts
16 years ago
drpudding's avatar drpudding

Thanks, Laisvunas, on both items.

       
stinhambo's avatar
stinhambo
1,268 posts
16 years ago
stinhambo's avatar stinhambo
Hi stinhambo, If you need that parent category which has only empty children would not be displayed, then set parameter “show_empty” to “no” and use the code as follows:

That’s pretty much the code I came up with but to no effect -

{parent_category_start}
    {if "{parent_category_children_count}" != "0"}
    <h3><a href="http://">{parent_category_name} - {parent_category_children_count}</a></h3>
    <div class="lessons">
        to download or view a lesson plan select from the lessons below
    {/if}
{parent_category_end}

I have attached a screenshot showing the result of {parent_category_children_count}

       
stinhambo's avatar
stinhambo
1,268 posts
16 years ago
stinhambo's avatar stinhambo

One thing to note is Little Champs has a child entry but Junior Champs doesn’t. But both report 1 entry…

Can I debug this somehow?

       
stinhambo's avatar
stinhambo
1,268 posts
16 years ago
stinhambo's avatar stinhambo

Got it working! I wrapped the plugin with a categories tag and used parent_only.

Curiously {weblog_url} works but {comment_url_title_auto_path} doesn’t. I hardcoded the template name in there but it would be nice to have this.

{exp:weblog:categories category_group="1" parent_only="yes" weblog="content_tutorials" style="linear"}
{exp:child_categories parent="{category_id}" show_empty="no" child_categories_sort_by="custom" child_categories_sort_direction="asc" entries_sort_by="date" entries_sort_direction="asc"}

{parent_category_start}
{if "{parent_category_children_count}" > "0"}
<h3><a href="http://">{parent_category_name} - {parent_category_children_count}</a></h3>
<div class="lessons">
    to download or view a lesson plan select from the lessons below
{/if}
{parent_category_end} 

{child_category_start}
<h4><a href="http://">{child_category_name}</a></h4>
<div class="lessons_downloads">
{child_category_end}

{entries_wrapper_top_start}
<ul>
{entries_wrapper_top_end}

{entries_start}
<li><a href="http://{weblog_url}detail/{url_title}">{title}</a>{!-- How to swing a raquet - <a href="#">Video (.mov) 5Mb</a> --}</li>
{entries_end}

{entries_wrapper_bottom_start}
</ul>
</div> <!-- lessons_downloads -->            
{entries_wrapper_bottom_end}

{parent_wrapper_bottom_start}
</div> <!-- lessons -->
{parent_wrapper_bottom_end}
                
{/exp:child_categories} 
{/exp:weblog:categories}
       
drpudding's avatar
drpudding
58 posts
16 years ago
drpudding's avatar drpudding

Laisvunas,

I wrote earlier about showing a single child category within a parent. I used your recommendation like this:

{exp:replace_plus parse="inward"}
        {exp:child_categories parse="inward" parent="{replace_area find="C"}{segment_2}{/replace_area}" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="no"}
    
        {parent_category_start}
            <h2>FAQs: {parent_category_name}</h2>
        {parent_category_end}

        {child_category_start}
        {if "{child_category_id}" == "{segment_3}"}
            <h3>{child_category_name}</h3>
        {/if}
        {child_category_end}
    
        {entries_wrapper_top_start}<div id="faqentries">{entries_wrapper_top_end}

        {entries_start}
        {if "{child_category_id}" == "{segment_3}"}
            <div class="question">Q: {exp:single_field field="f_question" weblog="{my_weblog}" entry_id="{entry_id}"}</div>
            <div class="answer">{exp:single_field field="f_answer" weblog="{my_weblog}" entry_id="{entry_id}"}</div>
        {/if}
        {entries_end}

        {entries_wrapper_bottom_start}</div>{entries_wrapper_bottom_end}
        
        {/exp:child_categories}
    {/exp:replace_plus}

This seems to work fine, but it renders the div wrapper top and bottom for all the children categories, even though they are not displayed, like this…

<div id=”faqentries”> </div> <div id=”faqentries”> </div> <div id=”faqentries”> </div> <div id=”faqentries”> </div> <div id=”faqentries”> </div>

etc.

Is there any way to avoid that?

Thanks!

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

Hi stinhambo,

When you run the code

{exp:child_categories weblog="content_tutorials" parent="1|2" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="no" entries_sort_by="date" entries_sort_direction="asc"}

{parent_category_start}
<h3><a href="http://">{parent_category_name} - {parent_category_children_count}</a></h3>
<div class="lessons">
    to download or view a lesson plan select from the lessons below
{parent_category_end}

{child_category_start}
<h4><a href="http://">{child_category_name}</a></h4>
<div class="lessons_downloads">
{child_category_end}

{entries_wrapper_top_start}
<ul>
{entries_wrapper_top_end}

{entries_start}
    <li>{title}<a href="http://">{title}</a></li>
{entries_end}

{entries_wrapper_bottom_start}
</ul>
</div> <!-- lessons_downloads -->
{entries_wrapper_bottom_end}

{parent_wrapper_bottom_start}
</div> <!-- lessons -->
{parent_wrapper_bottom_end}
                
{/exp:child_categories}

what outputs the variable {parent_category_children_count}? Does its output is as expected?

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

Hi drpudding,

In the next release of Child Categories plugin I will add support for {entries_total} variable pair inside {entries_wrapper_top_start}{entries_wrapper_top_end} and {entries_wrapper_bottom_start}{entries_wrapper_bottom_end}. Then using simple conditionals as this

{entries_wrapper_top_start}
{if "{entries_total}" > 0}
Some code
{/if}
{entries_wrapper_top_end}

you will avoid outputting unwanted code.

       
drpudding's avatar
drpudding
58 posts
16 years ago
drpudding's avatar drpudding

So for now, there is no alternative? No a big deal if there isn’t. I can wait.

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

It seems that changes needed are quite trivial. I plan to release the new version this or the next week.

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

Hi drpudding again,

I should correct myself. To solve your problem you need not support for {entries_total} variable, but rather support for {child_category_id} variable inside {entries_wrapper_top_start}{entries_wrapper_top_end} and {entries_wrapper_bottom_start}{entries_wrapper_bottom_end}. Then using simple conditionals as

{entries_wrapper_top_start}
{if "{child_category_id}" == "{segment_3}"}
<div id="faqentries">
{/if}
{entries_wrapper_top_end}

you will avoid outputting unwanted code.

       
stinhambo's avatar
stinhambo
1,268 posts
16 years ago
stinhambo's avatar stinhambo
Hi stinhambo, When you run the code… what outputs the variable {parent_category_children_count}? Does its output is as expected?

I have three entries assigned to the children of category parent one and none to category parent 2 but the {parent_category_children_count} shows two each.

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

Hi stinhambo,

The variable {parent_category_children_count} should output the number of child categories for given parent category. In case “show_empty” parameter is set to “no”, empty categories should not be counted.

So, you should check does in case “show_empty” parameter is set to “no” the variable {parent_category_children_count} outputs correct number of non-empty child categories for each parent category.

       
drpudding's avatar
drpudding
58 posts
16 years ago
drpudding's avatar drpudding

Laisvunas – I tried your suggestion, but it seems that {child_category_id} is not available inside {entries_wrapper_top_start}. Is that not supported yet?

Hi drpudding again, I should correct myself. To solve your problem you need not support for {entries_total} variable, but rather support for {child_category_id} variable inside {entries_wrapper_top_start}{entries_wrapper_top_end} and {entries_wrapper_bottom_start}{entries_wrapper_bottom_end}. Then using simple conditionals as
{entries_wrapper_top_start}
{if "{child_category_id}" == "{segment_3}"}
<div id="faqentries">
{/if}
{entries_wrapper_top_end}
you will avoid outputting unwanted code.
       
First 11 12 13 14 15 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.