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 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}
       
Gabriel's avatar
Gabriel
130 posts
16 years ago
Gabriel's avatar Gabriel

@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!

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

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.

       
Jonathan Schofield's avatar
Jonathan Schofield
175 posts
16 years ago
Jonathan Schofield's avatar Jonathan Schofield

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

on the top level only and the use of in-page anchors for the subcategory URLs. Now I almost achieved what I needed with {exp:child_categories} like so…
<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.

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

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.

       
Jonathan Schofield's avatar
Jonathan Schofield
175 posts
16 years ago
Jonathan Schofield's avatar Jonathan Schofield

Thanks for the swift reply, Laisvunas - I’ll think on that.

As it’s now the weekend here in the UK, I’m off to get some red wine. 😉

       
Ryan 2010's avatar
Ryan 2010
265 posts
16 years ago
Ryan 2010's avatar Ryan 2010

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:

  1. Add the status parameter to the tag: (for number of entries count, I need to restrict it by a certain status)
  2. Add the & option to the parameter: parent=”18&29;” (I need to show how many entries (count) that belong to both parent categories)

Thanks! Ryan

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

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.

       
Ryan 2010's avatar
Ryan 2010
265 posts
16 years ago
Ryan 2010's avatar Ryan 2010

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

       
Dragan Simonovic's avatar
Dragan Simonovic
71 posts
16 years ago
Dragan Simonovic's avatar Dragan Simonovic

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?

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

Where can I download this plugin???? It is not in the pluging’s list in EE site, I have been looking for this for long time 😊

Thanks

       
Les McKeown's avatar
Les McKeown
133 posts
16 years ago
Les McKeown's avatar Les McKeown

Try the first post in this thread 😊

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

Ayyy!! Thank you, but.. is that the latest version? I read there were some add-ons afterwards…

       
Les McKeown's avatar
Les McKeown
133 posts
16 years ago
Les McKeown's avatar Les McKeown

Laisvunas is usually pretty good at updating the file. Why not download it and take a look?

       
gennaria's avatar
gennaria
8 posts
16 years ago
gennaria's avatar gennaria

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

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