Datafeedr Support Forums

Datafeedr Support Forums (/index.php)
-   Questions (/forumdisplay.php?f=67)
-   -   If condition for child categories (/showthread.php?t=9247)

nokii June 17th, 2013 12:56 PM

If condition for child categories
 
Store ID: 42080

Hi,

I would like to display a category list IF there are any childs.
There is a widget that I can use for this but I need to display certain stuff before and after the list, stuff that don't work to place in the following line:

[category.list before=' ' after=' ']

Question: Is there any other PHP IF statement that I can execute in order to know if the certain category has childs?

Thanks in advance.

Eric June 17th, 2013 01:04 PM

Hi,

Just a thought, could you display your extra stuff like this:

<p>stuff above list</p>
[category.list before=' ' after=' ']
...
[/category]
<p>stuff below list</p>

If not there are conditionals such as these:

HTML Code:

[category.if active='self']
        display if THIS category is active
[/category.if]

[category.if active='child']
        display if one of the child categories of this category is active
[/category.if]

[category.if active='parent']
        display if one of the parent cats is active
[/category.if]

[category.if active='no']
        category is not in "activity chain"
[/category.if]

You can read much more about the [category] loop here: http://www.datafeedr.com/docs/item/169

Eric

nokii June 17th, 2013 01:17 PM

Thanks for the feedback Eric.

I've tried those loops without any succes. This is my code:

HTML Code:

<div class="btn-group" style="margin-left: 13px;margin-top: 9px;"><a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Kategori<span class="caret"></span></a><ul class="dropdown-menu">
[category.list before='' after='']
<li style="list-style-type: none;margin:0px;">
<a href="[category.link]" title="[category.name]">[category.name]</a>
</li>
[/category.list]
</ul></div>


As you may see I'll be having an empty dropdown menu if the category list is empty. That's what I want a work-around for.

I tried placing everything before the [category.list before='' after=''] in the before='' field. And then placing the last line in the after='' field, which didn't work.

I've now tried to place the [category.if active='child'] loop before [category.list before='' after=''], didn't work. Then I simply removed the "category.list" and kept the "category.if active='child' but no succes there either.

Do you see any misstakes? Maybe I'm not do it right.

I don't get an error, the dropdown is simpy missing.

Eric June 17th, 2013 01:20 PM

I think you need this:
HTML Code:

<div class="btn-group" style="margin-left: 13px;margin-top: 9px;">
        <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Kategori<span class="caret"></span></a>
        [category.list before='<ul class="dropdown-menu">' after='</ul>']
                <li style="list-style-type: none;margin:0px;"> <a href="[category.link]" title="[category.name]">[category.name]</a> </li>
        [/category.list]
</div>


nokii June 17th, 2013 01:29 PM

Yes I do get the dropdown and its child categories but when I navigate to a category without childs I get an empty dropdown due to that the "div" is defined before the category.list

I also tried this but the dropdown won't show up at all in this case:

[category.if active='child']
<div class="btn-group" style="margin-left: 13px;margin-top: 9px;">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Kategori<span class="caret"></span></a>
[category.list before='<ul class="dropdown-menu">' after='</ul>']
<li style="list-style-type: none;margin:0px;"> <a href="[category.link]" title="[category.name]">[category.name]</a> </li>
[/category.list]
[/category.if]

== just added the category.if statement.

Any ideas?

Eric June 17th, 2013 01:36 PM

I can't find this view in the Factory. What is its name?

nokii June 17th, 2013 01:40 PM

In my Store it's:

--> Views --> Category Page --> Default --> Category List

And in this module you'll find another dropdown at the top, this part is close to the bottom.

Eric June 17th, 2013 01:45 PM

Can you remove the category.if statement you put on that and update your store again so I can see what's going on on your site?

nokii June 17th, 2013 01:49 PM

Updated!

http://fajnd.se/store/category/iphone-5/

Eric June 17th, 2013 01:53 PM

Hi,

Try setting your "Maximum tree depth" to blank (ie. leave the field empty) here: The Factory > Your Store > VIEWS > CATEGORY PAGE > Default > Category list module > Settings ().

Eric

nokii June 17th, 2013 01:56 PM

Done. Now its logical, I should get the dropdown because there is no statement around it. So we need to define an if/loop statement so that we don't show it when there are no childs.

Eric June 17th, 2013 02:06 PM

Hi,

You still need to change this:
HTML Code:

[category.list before='<ul class="dropdown-menu">' after='</ul>']
    <li style="list-style-type: none;margin:0px;"> <a href="[category.link]" title="[category.name]">[category.name]</a> </li>
[/category.list]

To this:
HTML Code:

[category.list before='<ul class="dropdown-menu">' after='</ul>']
    <li style="list-style-type: none;margin:0px;">
            <a href="[category.link]" title="[category.name]">[category.name]</a>
            [category.repeat]
        </li>
[/category.list]

Eric

nokii June 17th, 2013 02:13 PM

Ok.

This is what I have right now:

<div class="btn-group" style="margin-left: 13px;margin-top: 9px;">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Kategori<span class="caret"></span></a>
[category.list before='<ul class="dropdown-menu">' after='</ul>']
<li style="list-style-type: none;margin:0px;">
<a href="[category.link]" title="[category.name]">[category.name]</a>
[category.repeat]
</li>
[/category.list]
</div>

Eric June 17th, 2013 02:30 PM

Hi,

Try replacing this:
HTML Code:

[category.list before='<ul class="dropdown-menu">' after='</ul>']
    <li style="list-style-type: none;margin:0px;">
      <a href="[category.link]" title="[category.name]">[category.name]</a>
      [category.repeat]
  </li>
[/category.list]

With this:
HTML Code:

<?php if (!empty($category->children)) : ?>
        [category.list before='<ul class="dropdown-menu">' after='</ul>']
                <?php if (!empty($category->children)) : ?>
                        <li class="dropdown-submenu" style="list-style-type: none;margin:0px;">
                <?php else : ?>
                        <li style="list-style-type: none;margin:0px;">
                <?php endif; ?>
                  <a href="[category.link]" title="[category.name]">[category.name]</a>
                  [category.repeat]
          </li>
        [/category.list]
<?php endif; ?>

Eric

nokii June 17th, 2013 02:38 PM

You nailed it Eric :)
I just moved the initial IF statement to a higher level so that it surounded the <div class="btn-group"> as well and everything worked out well.

Many thanks! I won't be bugging you more today, it's beginning to get late in Sweden ;)

Eric June 17th, 2013 02:43 PM

Quote:

Originally Posted by nokii (Post 42911)
You nailed it Eric :)
I just moved the initial IF statement to a higher level so that it surounded the <div class="btn-group"> as well and everything worked out well.

Excellent! I'm glad it worked for you.


All times are GMT -5. The time now is 01:16 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.