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

Tyssen's avatar
Tyssen
756 posts
15 years ago
Tyssen's avatar Tyssen

Thanks Laisvunas. I finally got it working and here’s what I did for anyone else who’s interested:

<ul class="sidenav">
      {if segment_3=="category"}{assign_variable:cat_url="{segment_4}"}{/if}
      {if segment_4=="category"}{assign_variable:cat_url="{segment_3}"}{/if}
      {exp:category_id category_group="8" weblog="services" category_url_title="{cat_url}"}
      {exp:child_categories category_group="8" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" parse="inward"}
            
        {parent_category_start}
        <li><a href="http://{homepage}{segment_1}/detail/category/{parent_category_url_title}/">{parent_category_name}</a>
        {if "{parent_category_children_count}" > 0 }
        {if segment_3=="category"}
        {if "{parent_category_url_title}" == "{segment_4}"}<ul class="subnav">{/if}
        {if:else}
        {if "{parent_category_url_title}" == "{segment_3}"}<ul class="subnav">{/if}
        {/if}
        {/if}
        {parent_category_end}
        
        {child_category_start}
        {if "{parent_category_url_title}" == "{segment_4}"}
        <li><a href="http://{homepage}{segment_1}/detail/{segment_4}/category/{child_category_url_title}/">{child_category_name}</a></li>
        {if:elseif "{parent_category_url_title}" == "{segment_3}"}
        <li><a href="http://{homepage}{segment_1}/detail/{segment_3}/category/{child_category_url_title}/">{child_category_name}</a></li>
        {/if}
        {child_category_end}
      
      {parent_wrapper_bottom_start}
      {if "{parent_category_children_count}" > 0 }{if "{parent_category_id}" == "{category_id}"}</ul>{/if}{/if}
      </li>
      {parent_wrapper_bottom_end}      
      
      {/exp:child_categories}
      {/exp:category_id}
      </ul>
       
datu's avatar
datu
3 posts
15 years ago
datu's avatar datu

Hi Laisvunas. Your plugin is awesome and it’s perfect for the project I am working on. However I can’t seem to wrap my head around something I need to achieve, even after reading the docs the whole day yesterday.

What i need to do is to wrap a single DIV around all child categories and entries of a parent category. Below is the structure I’m trying to produce:

<h2>Parent Category</h2>
<DIV>
   <h3>Child Category</h3>
   <ul><li>Entry</li></ul>
      
   <h3>Child Category</h3>
   <ul><li>Entry</li></ul>
</DIV>

<h2>Parent Category 2</h2>
<DIV>
   <h3>Child Category</h3>
   <ul><li>Entry</li></ul>
</DIV>

Below is the code I have (simplified). Those DIVs are really the only problem I’ve got.

{exp:child_categories}    
    {parent_category_start}
        <h2>{parent_category_name}</h2>
    {parent_category_end}
    
<DIV>
    {child_category_start}
        <h3>{child_category_name}</h3>
    {child_category_end}
        
    {entries_wrapper_top_start}<ul>{entries_wrapper_top_end}
        {entries_start}
        <li><a href="http://{weblog_url}{url_title}">{title}</a></li>
        {entries_end}
    {entries_wrapper_bottom_start}</ul>{entries_wrapper_bottom_end}    
</DIV>
{/exp:child_categories}

The reason i need that/those DIV(s) is because I am integrating this menu with the jQuery Accordion plug-in.

Your help would be appreciated. Thanks!

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

Hi,

Your code is wrong since nothing is rendered by the plugin what is outside the variable pairs

{parent_category_start}{parent_category_end} {child_category_start}{child_category_end} {entries_start}{entries_end} {entries_wrapper_top_start}{entries_wrapper_top_end} {entries_wrapper_bottom_start}{entries_wrapper_bottom_end} {child_wrapper_bottom_start}{child_wrapper_bottom_end} {parent_wrapper_bottom_start}{parent_wrapper_bottom_end}

About wrapping the output of variable pairs read this post.

       
datu's avatar
datu
3 posts
15 years ago
datu's avatar datu

Sorry for not being clear about my question. I was aware of my code being wrong and that nothing gets rendered outside the variable pairs. After some trial and error I got what i wanted. It just took me a while to fully understand {child_wrapper_bottom_start}{child_wrapper_bottom_end} and {parent_wrapper_bottom_start}{parent_wrapper_bottom_end}. My bad. Anyway, everything is working now. Thank you for the great plug-in!

       
onepanman's avatar
onepanman
44 posts
15 years ago
onepanman's avatar onepanman

Has anyone used this plug-in for navigation with a page that works with the Photo Gallery module (1st party)?

The page that handles the thumbnails works fine; however, when I click a thumbnail, using the image_full template, the categories are lost. Here is where it gets screwy. The image_full template works fine without the following /##/ {segment_4}, however, in order for the gallery to work that additional segment is required.

Linky to site: http://life.cc/index.php/media_arts/image_gallery

<ul id="nav_categories">
        {exp:weblog:entries weblog="media_arts" limit="1"} 
               {exp:weblog:categories weblog="media_arts" style="linear" parent_only="yes"}
                  {exp:child_categories parent="{category_id}" show_empty="yes" child_categories_sort_by="custom" entries_sort_direction="asc" site="1"}
                  {parent_category_start}
                      <li><a href="http://{site_url}index.php/{segment_1}/{parent_category_url_title}">{parent_category_name}</a></li>
                  {parent_category_end}
               {/exp:child_categories}
            {/exp:weblog:categories}
         {/exp:weblog:entries} 
    </ul>

Seems very basic, but it seems to always be the easy things I miss. Thanks for any help.

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

Hi,

Instead of using exp:weblog:categories you can use “category_group” parameter; also it seems that exp:weblog:entries tag is not needed in your code.

       
outline4's avatar
outline4
271 posts
15 years ago
outline4's avatar outline4

Hi there, seems usefull your plugin, though for me needs I would urgently need the following variables:

{parent_wrapper_top_start} {parent_wrapper_top_end}

I want to achieve a perfect structure:

<ul> <li> <ul><li></li></ul> </li> </ul>

my idea is to output the following code

{exp:weblog:categories weblog="jw_static" parent_only="yes" style="linear" show_empty="yes"}

    {exp:child_categories parse="inward" parent="{category_id}" show_empty="yes" child_categories_sort_by="custom" child_categories_sort_direction="asc"}
    
        {parent_category_start}
            <ul><li><!-- Opening part of the code which wrap parent category -->
            {parent_category_name}
        {parent_category_end}
      
      /// THE NEW BIT ///
      {child_wrapper_top_start}
            <ul><!-- Opening part of the code which wrap child category -->
        {child_wrapper_bottom_end}[/b]

        {child_category_start}
            <li><!-- Opening part of the code which wrap child category -->
             {child_category_name}
            </li>
        {child_category_end}
        
        {child_wrapper_bottom_start}
            </ul><!-- Closing part of the code which wrap child category -->
        {child_wrapper_bottom_end}
        
        {parent_wrapper_bottom_start}
            </li></ul><!-- Closing part of the code which wrap parent category -->
        {parent_wrapper_bottom_end}
    
    {/exp:child_categories}

{/exp:weblog:categories}

this would be highly appreciated! cheers stefan

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

The new variable pair

{child_wrapper_top_start}
{child_wrapper_top_end}

is not needed because you can achieve what you need using currently available variable pairs:

{exp:weblog:categories weblog="jw_static" parent_only="yes" style="linear" show_empty="yes"}

    {exp:child_categories parse="inward" parent="{category_id}" show_empty="yes" child_categories_sort_by="custom" child_categories_sort_direction="asc"}
    
        {parent_category_start}
            <ul><li><!-- Opening part of the code which wrap parent category -->
            {parent_category_name}
        {parent_category_end}

        {child_category_start}
            <ul><li><!-- Opening part of the code which wrap child category -->
            
             {child_category_name}

            </li></ul><!-- Closing part of the code which wrap child category -->
            
        {child_category_end}
        
        {parent_wrapper_bottom_start}
            </li></ul><!-- Closing part of the code which wrap parent category -->
        {parent_wrapper_bottom_end}
    
    {/exp:child_categories}

{/exp:weblog:categories}
       
outline4's avatar
outline4
271 posts
15 years ago
outline4's avatar outline4
The new variable pair
{child_wrapper_top_start}
{child_wrapper_top_end}
is not needed because you can achieve what you need using currently available variable pairs:
{exp:weblog:categories weblog="jw_static" parent_only="yes" style="linear" show_empty="yes"}

    {exp:child_categories parse="inward" parent="{category_id}" show_empty="yes" child_categories_sort_by="custom" child_categories_sort_direction="asc"}
    
        {parent_category_start}
            <ul><li><!-- Opening part of the code which wrap parent category -->
            {parent_category_name}
        {parent_category_end}

        {child_category_start}
            <ul><li><!-- Opening part of the code which wrap child category -->
            
             {child_category_name}

            </li></ul><!-- Closing part of the code which wrap child category -->
            
        {child_category_end}
        
        {parent_wrapper_bottom_start}
            </li></ul><!-- Closing part of the code which wrap parent category -->
        {parent_wrapper_bottom_end}
    
    {/exp:child_categories}

{/exp:weblog:categories}

I’ve tried your solution, but it’s not NESTING correctly

EVERY child category item gets an <ul><li></li></ul>. Now I only want to wrap ONE <ul></ul>pair around ALL child categories… EXACTELY like the {entries_wrapper_top_start}{entries_wrapper_top_end}, or why did you make this tag? semantically it’s incorrect to wrap each child element with an ul tag… Like here: (but with child category)

{entries_wrapper_top_start}<ul>{entries_wrapper_top_end}

{entries_start}
<li><a href="http://{weblog_url}{url_title}/">{title}</a> Weblog: {weblog_name}, posted: {entry_date}</li>
{entries_end}

{entries_wrapper_bottom_start}</ul>{entries_wrapper_bottom_end}

cheers stefan

       
outline4's avatar
outline4
271 posts
15 years ago
outline4's avatar outline4

I managed to get it work with the following code:

{exp:weblog:categories weblog="jw_static" parent_only="yes" style="linear" show_empty="yes"}

    {exp:child_categories parse="inward" parent="{category_id}" show_empty="yes" child_categories_sort_by="custom" child_categories_sort_direction="asc"}

        {parent_category_start}
                <ul><li>{parent_category_name}
        {parent_category_end}
        
        {child_category_start}
            {if {child_category_count} == 1}<ul>{/if}
                <li>{child_category_name}</li>
            {if {child_category_count} == {parent_category_children_count}}</ul>{/if}
        {child_category_end}
    
        {parent_wrapper_bottom_start}
                </li></ul>
        {parent_wrapper_bottom_end}
    
    {/exp:child_categories}

{/exp:weblog:categories}

it wasn’t logic for me… glad that it works now off to the next entry plugin 😉

       
Greg Griffith's avatar
Greg Griffith
37 posts
15 years ago
Greg Griffith's avatar Greg Griffith

I notice that when I use this tag:

{exp:child_categories parent="2" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" site="1"}

…everything works as expected.

But when I uses this:

{exp:child_categories parent="{cat_num}" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" site="1"}

… it doesn’t.

I’m creating {cat_num} with {assign_variable}, and echoing to the screen immediately before the tag to ensure it’s correct.

Can you tell me what I’m doing wrong?

Thanks.

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

Hi Greg,

I tried this code:

{assign_variable:parent_id="179"}



{exp:child_categories parent="{parent_id}" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="no" entries_sort_by="date" entries_sort_direction="asc" entries_limit="5" site="1" parse="inward" status="open|closed"}

{parent_category_start}
<ul><!-- Opening part of the tag which wraps parent category -->
Parent category: {parent_category_name}, child categories: {parent_category_children_count}
{parent_category_end}

{child_category_start}
<li><!-- Opening part of the tag which wraps child category -->
Category: {child_category_name}, {entries_total} entries
{child_category_end}

{entries_wrapper_top_start}
<ul><!-- Opening part of the tag which wraps entries -->
{entries_wrapper_top_end}

{entries_start}
<li>Entry: {count}. {title}</li>
{entries_end}

{entries_wrapper_bottom_start}
</ul><!-- Closing part of the tag which wraps entries -->
{entries_wrapper_bottom_end}

{child_wrapper_bottom_start}
</li><!-- Closing part of the tag which wraps child category -->
{child_wrapper_bottom_end}

{parent_wrapper_bottom_start}
</ul><!-- Closing part of the tag which wraps parent category -->
{parent_wrapper_bottom_end}

{/exp:child_categories}

and found that it works as expected.

       
Greg Griffith's avatar
Greg Griffith
37 posts
15 years ago
Greg Griffith's avatar Greg Griffith

Laisvunas,

Thank you for taking a look at this, and for your sample code.

I tried your method:

{assign_variable:parent_id="179"}

…and it did work. My problem is that I need to set that {parent_id} number dynamically based on the C# that comes in through the URL.

What I’m doing is this:

<?php

$cat_num = "{segment_3}";
$cat_num = ltrim($cat_num, "C");

?>

{assign_variable:parent_id="<?php echo $cat_num; ?>"}

{parent_id} is correct; wherever in the page I put

{parent_id}

… whether it’s outside your tag, inside your main tag, inside the child tag, I get the expected parent category id.

But when I use this:

{exp:child_categories parent="{parent_id}" child_categories_sort_by="custom" child_categories_sort_direction="asc" site="1" show_empty="yes"}

    {child_category_start}

        <li>
            <a href="http://cat/{child_category_id}">_            <span class="catLinkTitle">{child_category_name}</span>_            <span class="catLinkSub">{child_category_description}</span>_            </a>
        </li>

    {child_category_end}

{/exp:child_categories}

…all I get are the sibling categories, not the child categories.

Only when I hard-code the {parent_id} value do I get the child categories, but obviously that’s not going to work in a dynamic situation.

Any ideas?

       
Greg Griffith's avatar
Greg Griffith
37 posts
15 years ago
Greg Griffith's avatar Greg Griffith

Laisvunas,

Strike all that. My apologies. I changed the PHP parsing stage to “input” and everything’s fine.

:red:

       
OutofControl's avatar
OutofControl
164 posts
15 years ago
OutofControl's avatar OutofControl

Hello Laisvunas,

Your plugin is a wonderful and has saved me a lot of grief. However, I can’t seem to get it to do exactly what I need. My worry is that I am over-complicating everything.

Here is what I have now and it works as it should, showing a nested UL list of categories and their weblog entries for a specific parent category based on the category_url_title.

<ul>
{exp:category_id category_group="1" category_url_title="{division}" parse="inward"}
{exp:child_categories parent="{category_id}"  show_empty="no" child_categories_sort_by="custom" }
{child_category_start}
<li class="cat-{child_category_url_title}"><a href="/{division}/category/{child_category_url_title}class=catbutton"><span>{child_category_name}</span></a>
{child_category_end}

{entries_wrapper_top_start}<ul>{entries_wrapper_top_end}
{entries_start}
<li><a href="http://{path=/{division}}{url_title}/">{title}</a></li>
{entries_end}
{entries_wrapper_bottom_start}</ul></li>{entries_wrapper_bottom_end}

{child_wrapper_bottom_start}{child_wrapper_bottom_end}
{/exp:child_categories}
{/exp:category_id}
</ul>

What I need now is simply to be able to restrict which children categories are shown. For example, in each parent category, there is one category that I don’t want to show in one section, and then I want to display those categories in a separate section. I have tried to use the following with no success:

{child_category_start}
{if child_category_id == '53'}
<li class="cat-{child_category_url_title}"><a href="/{division}/category/{child_category_url_title}class=catbutton"><span>{child_category_name}</span></a>
{/if}

When I try try this code with the first block of code, all of the children categories still show, and not just child_category_id 53. Ideally what I need is to have something where I can say

{if child_category_id != '50|51|52|53'}

Would you have any suggestions for this situation?

Thanks

       
First 17 18 19 20 21 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.