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

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

@Calan Most downloads are PDFs that’s why I want to include a Download Adobe Reader link in the sidebar of those pages. They are not necessary anywhere else. What I am looking for is a solution where the Link gets included automatically to all Category Children of the Category Downloads. It should be as easy as possible for my client as I don’t want them to have to always remember to add another category or myself have to edit the template code should they decide to add another child to the Download category. Hope that clears it up a bit.

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

Hi Andy,

From your post, I don’t understand what the need for the different categories is? I guess mainly because you’re naming them ‘Download Section 1’, ‘Download Section 2’, etc. which doesn’t offer much info as to why the need for different categories?

Can I assume that ‘Section 1’ for instance is ‘Medical Software’, and ‘Section 2’ is ‘Finance Software’? That would explain the need.

Anyway, assuming you need to keep them, you’re essentially wanting to pull the parent category ID for the current category and populate the link based on that. you could do this by using either the category heading tag as follows:

{exp:weblog:category_heading}
  {if parent_id = '99'}
    PRINT ME
  {/if}
{/exp:weblog:category_heading}

Or by initiating a query that retrieves the parent_id from the DB for a defined category ID and evaluating based on the result.

I’d definitely try and avoid a plugin unless required because as per my post above yours, the plugin will iterate through all categories and sub-categories and generate queries for each. This isn’t a problem if you have a few, but trust me it gets unusable if you have a lot (I have 800 categories in a site and it was bringing down the server).

Calan

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

Hi Calan,

I used Download Section 1 etc. as example names. They do have different names in reality but in German which wouldn’t mean much to people who don’t speak German anyway. 😉 I will try the exp:weblog:category_heading tag.

Thanks Andy

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

Ok doesn’t really work the way I want it. Might be missing something small.

The website in question is located here: http://temp.kibiz-zuerich.ch/index.php/ueber-uns/download-kinderhort/ When using

{exp:weblog:category_heading weblog='{segment_1}' disable='category_fields'}
          {if parent_id == '27'}
            <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}
        {/exp:weblog:category_heading}

Nothing shows up. When using

{exp:weblog:categories weblog='{segment_1}' disable='category_fields'}
          {if parent_id == '27'}
            <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}
        {/exp:weblog:categories}

It shows up - but three times. I just need it to display once. Thanks for any help.

Andy

       
wondermade's avatar
wondermade
53 posts
16 years ago
wondermade's avatar wondermade

I’ve read through this thread and can’t figure out what I’m missing… I’d like to show all the post from all the child categories of a parent category. I’d like them all sorted chronologically, like:

{exp:weblog:entries weblog="blogs" category="

{exp:child_categories parent="75" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" entries_sort_by="date" entries_sort_direction="asc" entries_limit="20" site="1" }
                        {child_category_start}
                        {child_category_id}
                        {child_category_end}
                    {/exp:child_categories}

" limit="3"}

Obviously, that doesn’t work. I can’t use PHP because of the parse order - is there a way to achieve this with this plugin that I’m missing?

Thanks for the help!

       
brittanyA's avatar
brittanyA
184 posts
about 16 years ago
brittanyA's avatar brittanyA

Is there way to say {if segment_n has a parent category}{parent category name}? Basically, I need to detect whether a segment variable is a child category and, if so, pull the url_title and name of the parent category. I’ve played around with every possible combination and just can’t figure this out!

Thanks!

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

Hi all

I may be barking up the wrong tree here, but can I output custom category fields with the child categories plugin? I’m guessing not but haven’t been able to find any definitive answer yet (unless I’ve just missed it!).

Cheers

Jim

       
gwineman's avatar
gwineman
19 posts
about 16 years ago
gwineman's avatar gwineman

Hello all

I think this plugin may help me with a problem I’m having… I’ve looked through this thread and don’t quite see what I’m looking for yet.

I need to filter entries by categories and/or subcategories on one template

When the user first comes to the page, I list all top level categories in the left nav and show all entries in the content area

Left Nav would look like this: Cat Cat Cat Cat

If a User clicks on a category in the left nav, I want to reload the page with a filtered result set, and expose the subcategories in the left nav

Cat Cat (Selected) -SubCat -SubCat -SubCat Cat Cat

the url structure would be /template/category

If a user clicks on a subcategory from the left nav, I want to reload the page again and further filter the result set

the url structure would be /template/subcategory

I want to show the left nav again with the proper category expanded and list the subcats again (with a class of selected)

It seems like this will do the trick, but I need a little coaching.

Any help appreciated.

Thanks

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

Hi gwineman,

You code should be approximately as follows:

{exp:child_categories category_group="your_category_group_id"}

{parent_category_start}
<a href="http://{homepage}/your_template/{parent_category_url_title}/">{parent_category_name}</a>

{parent_category_end}

{child_category_start}
{if "{segment_2}"=="{parent_category_url_title}"}
{child_category_name}

{/if}
{child_category_end}

{exp:child_categories}
       
gwineman's avatar
gwineman
19 posts
about 16 years ago
gwineman's avatar gwineman

Thanks - Awesome plugin and your suggestion is almost perfect… Just one small question

If I’m on a subcategory page, i want the highlight the top level in the nav. Here’s my code. I need to check subcategory in the parent_category pair (Where I noted below) Is there any way to do this?

<ul>
{exp:child_categories category_group="1"}
    
        {parent_category_start}
        <li {if "{segment_2}"=="{parent_category_url_title}" (OR SUBCATEGORY) }class="on"{/if}><a href="/projects/{parent_category_url_title}/">{parent_category_name}</a></li>
        {parent_category_end}
    
        <ul>
            {child_category_start}
            
                {if "{segment_2}"=="{parent_category_url_title}" OR "{segment_2}" == "{child_category_url_title}"}
                <li{if "{segment_2}" == "{child_category_url_title}"} class="on"{/if}>{child_category_name}</li>
                {/if}
            
            {child_category_end}
        </ul>
{/exp:child_categories}
</ul>
       
Laisvunas's avatar
Laisvunas
879 posts
about 16 years ago
Laisvunas's avatar Laisvunas

Hi gwineman,

Try such code:

<ul>
{exp:child_categories category_group="1"}
    
        
            {child_category_start}
{if "{child_category_count}"=="1"}
          <li {if "{segment_2}"=="{parent_category_url_title}"  OR "{segment_2}" == "{child_category_url_title}"}class="on"{/if}><a href="/projects/{parent_category_url_title}/">{parent_category_name}</a></li>
{/if}
            <ul>
                {if "{segment_2}"=="{parent_category_url_title}" OR "{segment_2}" == "{child_category_url_title}"}
                <li{if "{segment_2}" == "{child_category_url_title}"} class="on"{/if}>{child_category_name}</li>
                {/if}
             </ul>
            {child_category_end}
       
{/exp:child_categories}
</ul>
       
gwineman's avatar
gwineman
19 posts
about 16 years ago
gwineman's avatar gwineman

That’s perfect - Thank you for a great plugin

       
Lunchbox Collective's avatar
Lunchbox Collective
75 posts
15 years ago
Lunchbox Collective's avatar Lunchbox Collective

Laisvunas, I was really struggling with some child/parent relationship code, and am really glad that I found your plugin.

But I am having one issue: pulling data for a Custom Field variable.

I have tried a couple different ways inside of the {entries_start} - {entries_end}, with no luck.

When I use this code:

{entries_start}
  {exp:weblog:entries entry_id="{entry_id}"}
    File - <strong>{file-upload}</strong>
  {/exp:weblog:entries}
  <li><a href="http://{file-upload}" title="{title}">{title}</a> - {entry_id}</li>
{entries_end}

Here is the output:

<li><a href="http://{file-upload}" title="SB A119-303-REV A">SB A119-303-REV A</a> - 140</li>

It prints the {entry_id} just fine right after the href, but when trying to pass it as a variable to the {exp:single_field}, I don’t get any output.

I tried hardcoding an id into {exp:single_field field="file-upload" weblog="bulletins" entry_id="140"}, and it works just fine, printing out the name of my file.

Here is the output:

File - <strong>SBA119-303-REVA.PDF</strong>
<li><a href="http://{file-upload}" title="SB A119-303-REV A">SB A119-303-REV A</a> - 140</li>

I cannot seem to figure out why it is not passing the variable correctly. Any help would be great - thanks.

       
Gabriel's avatar
Gabriel
130 posts
15 years ago
Gabriel's avatar Gabriel

Hi, I’m trying create very simple category structure as navgation menu. The working source code si bellow.

<ul>
   <li>
     <h2><a href="#">Parent category</a></h2>
     <ul>
        <li><a href="#">child ctegory 1</a> (8)</li>
        <li><a href="#">child ctegory 2</a></li>
        <li><a href="#">child ctegory 3</a> (2)</li>
      </ul>
   </li>
</ul>
<ul>{exp:child_categories parent="1" child_categories_sort_by="custom" show_empty="yes"}
    {parent_category_start}
    <li>
      <h2><a href="#">{parent_category_name}</a></h2>
      <ul>
      {parent_category_end}
        {child_category_start}<li{if segment_2 == "{child_category_url_title}"} class="current"{/if}><a href="#">{child_category_name}</a>{if "{entries_total}" > 0} ({entries_total}){/if}</li>
        {child_category_end}
        {/exp:child_categories}
      </ul>
    </li>
    </ul>

The problem I’m trying to resolve is the highlighting current menu item depending on displayed segment_2. I’m trying display class=”current” for li but without success.

<li{if segment_2 == "{child_category_url_title}"} class="current"{/if}>

or

<li{if child_category_url_title == "{segment_2}"} class="current"{/if}>

or

<li{if {child_category_url_title} == "{segment_2}"} class="current"{/if}>

No one doesn’t work. Could you help me how to make highlighting?

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

Hi Lunchbox Collective,

Use Child Categories together with Single field plugin:

{entries_start}
  <li><a href="{exp:single_field id=" field="file-upload" site="1" format="none" title="{title}"> - {entry_id}</li>
{entries_end}

(&quot; means double quotation mark). Also you should add

parse="inward"

to exp:child_categories tag.

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