Hi Gabriel,
It should be possible in case you post entries having Parent category 1 and entries having Parent category 2 into the same weblog.
You should use parse=”inward” for exp:child_categories tag and exp:weblog:entries tag inside {child_category_start}{child_category_end}.
The code would be approximately as follows:
{exp:child_categories parent="5" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" entries_sort_by="date" entries_sort_direction="asc" site="1" parse="inward"}
{parent_category_start}
<h1><a href="http://{homepage}entry/{parent_category_url_title}/">{parent_category_name}</a></h1>
{parent_category_end}
{child_category_start}
<h2><a href="http://{homepage}entry/{child_category_url_title}/">{child_category_name}</a></h2>
From {exp:weblog:entries weblog="my_weblog" sort="asc" limit="1"}{entry_date format="%Y %m %d"}{/exp:weblog:entries} to {exp:weblog:entries weblog="my_weblog" sort="desc" limit="1"}{entry_date format="%Y %m %d"}{/exp:weblog:entries}
Performances: {entries_total}
{child_category_end}
{/exp:child_categories}
@Laisvunas: There is needed add category=”{child_category_id}” parameter to the exp:weblog:entries
{exp:child_categories parent="5" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" entries_sort_by="date" entries_sort_direction="asc" site="1" parse="inward"}
{parent_category_start}
<h1><a href="http://{homepage}entry/{parent_category_url_title}/">{parent_category_name}</a></h1>
{parent_category_end}
{child_category_start}
<h2><a href="http://{homepage}entry/{child_category_url_title}/">{child_category_name}</a></h2>
From {exp:weblog:entries weblog="my_weblog" sort="asc" limit="1" category="{child_category_id}"}{entry_date format="%Y %m %d"}{/exp:weblog:entries} to {exp:weblog:entries weblog="my_weblog" sort="desc" limit="1" category="{child_category_id}"}{entry_date format="%Y %m %d"}{/exp:weblog:entries}
Performances: {entries_total}
{child_category_end}
{/exp:child_categories}
I’ts working great now. Thank you!
Hi all,
I have released version 1.4.2 of Child Categories plugin.
In this release a bug reported by tristanbailey in this post - PHP errror messages such as these being thrown -
Notice: Undefined variable: parent_cat_description in /home/public_html/core/plugins/pi.child_categories.php on line 426
Notice: Undefined variable: parent_cat_image in /home/public_html/core/plugins/pi.child_categories.php on line 427
was fixed.
Loving the possibilities of this plugin. It’s almost the answer to what I’m trying to achieve. If I’ve missed something, perhaps it already is. I’m fairly new to EE so that’s distinctly possible!
The challenge
I started out using the nested option of the {exp:weblog:categories} tag. But the problem with that seems to be that there are no options to vary the HTML output between nested levels, so I can’t use that tag to produce something like this:
<ul>
<li>
<h2><a href="http://{homepage}/{weblog_name}/{category_name}/">{category_name}</a></h2>
<ul>
<li>
<a href="http://{homepage}/{weblog_name}/#{category_name}">{category_name}</a>
</li>
</ul>
</li>
</ul>
Note the use of
<ul>
{exp:child_categories parent="17|18|19|20|21|72" child_categories_sort_by="custom" show_empty="yes" }
{parent_category_start}
<li><h2><a href="http://{homepage}/{weblog_name}/{parent_category_url_title}/">{parent_category_name}</a></h2>
<pre><code><ul>
{parent_category_end}
{child_category_start}
<li><a href="http://{homepage}/{weblog_name}/{parent_category_url_title}/#{child_category_url_title}">{child_category_name}</a></li>
{child_category_end}
</ul>{!-- close list of child categories --}
</li>{!– close parent category list item –}
{/exp:child_categories} </ul>
But then I read that…
No code should be outside variable pairs
…which explains why my child lists aren’t getting closed.
Interim conclusion
It seems a shame that there are code ‘wrapper’ options around lists of entries but not for their ‘parent’ child categories, or have I missed something obvious?
I guess I could achieve what I want with a more verbose set of {exp:child_categories} tags, one for each parent category…
<ul>
{exp:child_categories parent="17" child_categories_sort_by="custom" show_empty="yes" }
{parent_category_start}
<li><h2><a href="http://{homepage}/{weblog_name}/{parent_category_url_title}/">{parent_category_name}</a></h2>
<ul>
{parent_category_end}
{child_category_start}
<li><a href="http://{homepage}/{weblog_name}/{parent_category_url_title}/#{child_category_url_title}">{child_category_name}</a></li>
{child_category_end}
{/exp:child_categories}
</ul>{!-- close list of child categories --}
</li>{!-- close parent category list item --}
{exp:child_categories parent="18" child_categories_sort_by="custom" show_empty="yes" }
{parent_category_start}
<li><h2><a href="http://{homepage}/{weblog_name}/{parent_category_url_title}/">{parent_category_name}</a></h2>
<ul>
{parent_category_end}
{child_category_start}
<li><a href="http://{homepage}/{weblog_name}/{parent_category_url_title}/#{child_category_url_title}">{child_category_name}</a></li>
{child_category_end}
{/exp:child_categories}
</ul>{!-- close list of child categories --}
</li>{!-- close parent category list item --}
[etc...]
</ul>
But that seems inefficient. Any help much appreciated.
Hi watershed,
Currently you can get list of child categories closed using this code:
<ul>
{exp:child_categories parent="17|18|19|20|21|72" child_categories_sort_by="custom" show_empty="yes" }
{parent_category_start}
<li><h2><a href="http://{homepage}/{weblog_name}/{parent_category_url_title}/">{parent_category_name}</a></h2>
{parent_category_end}
{child_category_start}
<ul><li><a href="http://{homepage}/{weblog_name}/{parent_category_url_title}/#{child_category_url_title}">{child_category_name}</a></li>
{child_category_end}
{entries_wrapper_top_start}{entries_wrapper_top_end}
{entries_start}{entries_end}
{entries_wrapper_bottom_start}
</ul>{!-- close list of child categories --}
{entries_wrapper_bottom_end}
{/exp:child_categories}
</ul>
You cannot close the list of parent categories - that’s the limitation. I will think about it.
But perhaps it is enaugh to be able to close list of child categories?
If closing list of parent categories is badly needed, then there is some kind of better solution than repeating manually the code for each parent category. You can try using Loop plugin together with Child categories plugin:
{exp:for_loop start="17" end="21" increment="1" parse="inward"}
<ul>
{exp:child_categories parent="{index}" child_categories_sort_by="custom" show_empty="yes" }
{parent_category_start}
<li><h2><a href="http://{homepage}/{weblog_name}/{parent_category_url_title}/">{parent_category_name}</a></h2>
<ul>
{parent_category_end}
{child_category_start}
<li><a href="http://{homepage}/{weblog_name}/{parent_category_url_title}/#{child_category_url_title}">{child_category_name}</a></li>
{child_category_end}
{/exp:child_categories}
</ul>{!-- close list of child categories --}
</li>{!-- close parent category list item --}
</ul>
{/exp:for_loop}
<ul>
{exp:child_categories parent="72" child_categories_sort_by="custom" show_empty="yes" }
{parent_category_start}
<li><h2><a href="http://{homepage}/{weblog_name}/{parent_category_url_title}/">{parent_category_name}</a></h2>
<ul>
{parent_category_end}
{child_category_start}
<li><a href="http://{homepage}/{weblog_name}/{parent_category_url_title}/#{child_category_url_title}">{child_category_name}</a></li>
{child_category_end}
{/exp:child_categories}
</ul>{!-- close list of child categories --}
</li>{!-- close parent category list item --}
</ul>
This solution depends on your category id numbers being in a numerical sequence.
Hi Laisvunas,
Thanks so much for doing this program.. I’m struggling in PHP to come up with a lot of what you have done already. A friend just recently alerted me to your plugin!
I was wondering if it would be possible to have the following:
Thanks! Ryan
Hi Ryan,
I will think about adding “status” parameter to exp:child_categories tag.
In order to find how many entries there are posted into two parent categories you can use Enties Number plugin.
Hi Laisvunas,
Thanks for considering using the status parameter. Right now I’m using bulky php and sql queries to accomplish what your plugin would do if I could restrict the results by Status.
Thanks for letting me know about the entries number plugin. I’ve tried it out and posted a question in your entries number forum.
Thanks again!
Ryan
I have a problem to display single child category title on the page. The code below display all child category titles in a loop.
{exp:category_id category_group="2" category_url_title="{segment_4}" parse="inward"}
{exp:child_categories parent="{category_id}" parse="inward" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" entries_sort_by="date" entries_sort_direction="asc" entries_limit="1" site="1"}
{child_category_start}
{exp:weblog:category_heading weblog="news" category_group="2"}
<h1>Category: <strong>{child_category_name}</strong></h1>
{if category_description}{child_category_description}{/if}
{/exp:weblog:category_heading}
{child_category_end}
{/exp:child_categories}
{/exp:category_id}
How to limit the code above to display chosen child category title?
This plugin combined with the Category ID plugin is almost exactly what I need.
Is there a way to display something if their are no children for a parent? Like this:
{exp:category_id category_group="3" category_url_title="{segment_3}" parse="inward"}
{exp:child_categories weblog="music" parent="{category_id}" parse="inward" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes"}
{if no_results}
Sorry there are no children categories
{/if}
{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}
Thanks, jerry
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.