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

james Brown's avatar
james Brown
492 posts
16 years ago
james Brown's avatar james Brown

I bet it is a plugin parsing order. Perhaps adding a parse=”inward” to your {exp:child_categories} tag will fix it?

       
Jim Pannell's avatar
Jim Pannell
187 posts
16 years ago
Jim Pannell's avatar Jim Pannell

Spot on! That worked - thanks a lot 😊 You’ve gotta love the EE community - magic things happen - and quickly!

       
Jordan Moore's avatar
Jordan Moore
45 posts
16 years ago
Jordan Moore's avatar Jordan Moore

Hey guys,

Two questions:

1 - can the child categories be limited to the amount shown for example show only 3 with a link to view all?

2 - can individual child categories be excluded from the listing?

Thanks in advance! Jordan

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

Hi Jordan,

To show only 3 child categories use conditional as this:

{if "{child_category_count}" == "1" OR "{child_category_count}" == "2" OR "{child_category_count}" == "3"}
Some code
{/if}

To exclude individual child categories from list use conditional as this:

{if "{child_category_id}" != "10" AND "{child_category_id}" != "15" AND "{child_category_id}" != "21"}
Some code
{/if}
       
Jordan Moore's avatar
Jordan Moore
45 posts
16 years ago
Jordan Moore's avatar Jordan Moore

Hey Laisvunas,

Awesome, thank you very much for the quick reply and terrific plugin!

Thanks, Jordan

       
Brad Parscale's avatar
Brad Parscale
196 posts
16 years ago
Brad Parscale's avatar Brad Parscale

Hello, really need your help.

I am using this code:

{exp:child_categories category_group="2" entries_limit="none" status="open"}

{parent_category_start}
<a href="http://{site_url}services/category/{parent_category_url_title}">{parent_category_name}</a>

{parent_category_end}

{entries_start}
<a href="http://{site_url}services/detail/{url_title}/">{title}</a>

{entries_end}


{/exp:child_categories}

I however am getting no entries. What could be causing this?

Brad

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

Hi Brad,

Go through all weblogs’ “Edit groups” and check if status group having status “open” (most probably default status group) is assigned to the weblog.

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

Hi Laisvunas,

I have the following code -

{exp:weblog:categories category_group="1" show_empty="no" parent_only="yes" weblog="content_tutorials" style="linear"}

{exp:child_categories parent="{category_id}" show_empty="no" parse="inward" 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}</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://{exp:single_field">{title} ({exp:single_field field="tutorials_file_type" entry_id="{entry_id}"})</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}

and my output comes out as -

<h3><a href="http://">Little Champs - 4-6 Years</a></h3>
<div class="lessons">
to download or view a lesson plan select from the lessons below
                                
<h4><a href="http://">Little Champs Lesson B</a></h4>

<div class="lessons_downloads">
                  
<ul>
<li><a href="http://">How to swing a raquet ()</a></li>            
<li><a href="http://">Another Tutorial ()</a></li>    
</ul>

</div> <!-- lessons_downloads -->
                
</div> <!-- lessons -->

                 
                

                
                                
</div> <!-- lessons -->
                 
                                
                                
</div> <!-- lessons -->
 
                                
                                
</div> <!-- lessons -->

Any ideas how I can prevent these extra closing divs?

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

Hi stinhambo,

To quote from the reply #196:

New features: […] 4) support for {entries_total} and {child_category_id} variables inside {entries_wrapper_top_start}{entries_wrapper_top_end} variable pair. 5) support for {entries_total} and {child_category_id} variables inside {entries_wrapper_bottom_start}{entries_wrapper_bottom_end} variable pair. 6) support for {entries_total} and {child_category_id} variables inside {child_wrapper_bottom_start}{child_wrapper_bottom_end} variable pair. 7) support for {parent_category_children_count} and {parent_category_id} variables inside {parent_wrapper_bottom_start}{parent_wrapper_bottom_end} variable pair.

So, you can avoid unneeded closing tags by writing the code as here:

{entries_wrapper_bottom_start}
{if "{entries_total}" > 0}
</ul>
</div> <!-- lessons_downloads -->
{/if}
{entries_wrapper_bottom_end}

{parent_wrapper_bottom_start}
{if "{parent_category_children_count}" > 0}
</div> <!-- lessons -->
{/if}
{parent_wrapper_bottom_end}
       
stinhambo's avatar
stinhambo
1,268 posts
16 years ago
stinhambo's avatar stinhambo

Awesome it works!

Great work mate.

       
Calan's avatar
Calan
104 posts
16 years ago
Calan's avatar Calan

Hi Laisvunas,

Your plugin works brilliantly. The one problem I am having though is that it is adding a huge number of queries to my page, in this case, 94. Using the code below, it generates a query for every parent category and every child category in the specified group.

Would you have any ideas as to why this would be?

{exp:child_categories weblog="{segment_1}" category_group="{embed:my_category_group}" show_empty="no" site="1"}
    {parent_category_start}
    <h5><a href="http://{homepage}{my_weblog}/region/category/{parent_category_url_title}/">{parent_category_name}</a></h5>
    <ul class="list-type-0">
    {parent_category_end}
    
    {child_category_start}
    <li><a href="http://{homepage}{my_weblog}/town/category/{child_category_url_title}/">{child_category_name} ({entries_total})</a></li>
    {child_category_end}
    
    {parent_wrapper_bottom_start}</ul><div class="clear listmargin"> </div>{parent_wrapper_bottom_end} 
{/exp:child_categories}

Cheers, Calan

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

Hi Calan,

Child Categories plugin does many things; so, you should not wonder that it makes many calls to SQL server.

Of course, some calls might be saved by making SQL queries more efficient or by introducing “disable” parameter. But I doubt that such efficiency is really worth to strive at. If you do not have several thousands of categories or do not instantiate Child Categories plugin hundreds of times in one template you will hardly ever experience longer page load time or max out some PHP or SQL variable.

       
Calan's avatar
Calan
104 posts
16 years ago
Calan's avatar Calan

Hi Laisvunas,

Thanks for the reply. The problem is that it iterates through every category and sub-category and creates queries for each. I had a template that was generating over 2000 queries and was causing all sorts of problems to the server, but when removed, the same page uses 30 queries. This was purely to generate a couple of category lists which I’ve now done as static blocks.

Regards, Calan

       
Andy_vdG's avatar
Andy_vdG
62 posts
16 years ago
Andy_vdG's avatar Andy_vdG

Hi,

I have a download section on a website I am working on. It’s structured like this: Downloads - Download Section 1 - Download Section 2 - Download Section 3

On these pages I would like to display a download Adobe Reader link. So I hard coded it like this:

{if segment_2 == 'download' OR segment_2 == 'download-1' OR segment_2 == 'download-2' OR segment_2 == 'download-3'}
            <a href="http://www.adobe.com/go/DE_CH-H-M-A1" title='Get Adobe Reader'>/images/site/icons/get_adobe_reader.png</a>
        {/if}

This works fine until someone creates Download Section 4. Is there any way I can use your plugin to dynamically create that IF statement?

Thanks

       
Calan's avatar
Calan
104 posts
16 years ago
Calan's avatar Calan

Hi Andy,

In what way do the categories relate to the adobe reader?

You probably have a reason but it would seem you might be better off using a custom category field to store whether the category requires the adobe reader, or alternatively doing it on a product/entry basis where a custom field against the product/entry defines whether to display the link?

{if requires_adobe == "yes"}
  <a href="#" title='Get Adobe Reader'>Adobe</a>
{/if}

Not sure this helps but difficult without knowing the context of what you’re trying to do.

C

       
First 14 15 16 17 18 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.