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}
Hi drpudding’
{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}
{child_category_start}
{if "{child_category_count}" == "1"}
{child_category_name}
{/if}
{child_category_end}
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}
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}
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!
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?
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.
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.
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.
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.
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 asyou will avoid outputting unwanted code.{entries_wrapper_top_start} {if "{child_category_id}" == "{segment_3}"} <div id="faqentries"> {/if} {entries_wrapper_top_end}
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.