开发者

Expression Engine - Breadcrumbs problem!

OK, I have set-up my breadcrumbs trial using IF segment and IF category_id statements. The reason being is because I have different products linking into 2-3 categories etc...

I h开发者_JAVA百科ave completed the whole trial and all works fine (alot of coding though!)

However, ONE category i'm having a big issue with, i've tried for hours to rectify it but can't, basically this category is in 2 parents and 2 children categories, under the one category group... All of the others have only one parent and one child so my code works fine.

I've tried everything, but it is bringing up

Toys >> Ben 10 >> Children >> Ben 10

It's repeating both categories and parents because the entry is in both of these in the one group... So I tried creating two seperate if statements away from my main if statement, like this:

My code is:

{if segment_2 == "view"}
    {exp:channel:entries channel="toys"}
    {categories}
    {if parent_id == "25"}
    {if category_id == "31"}
    <li>
    <a href="(URL TO CATEGORY)">Toys</a>
    </li>
    <li>
    <a href="{path='toys/list'}">{category_name}</a>
    </li>
    {/if}
    {/if}
    {/categories}
    {/exp:channel:entries}
{/if}

{if segment_2 == "view"}
    {exp:channel:entries channel="toys"}
    {categories}
    {if parent_id == "26"}
    {if category_id == "40"}
    <li>
    <a href="(URL TO CATEGORY)">Children</a>
    </li>
    <li>
    <a href="{path='toys/list'}">{category_name}</a>
    </li>
    {/if}
    {/if}
    {/categories}
    {/exp:channel:entries}
{/if}

I would have assummed that defining the specific parent and cat id that this would display only one...

Any solutions?


For debugging purposes, it's often helpful to understand and "visualize" what the structure of the data you're dealing with is.

To get a sense of the categories you're trying to wrangle for your breadcrumbs trail, use the following code to output each categories' parent_id and category_id:

{exp:channel:entries channel="toys"}
    {categories}
        <strong>{category_name}</strong> [{parent_id}, {category_id}]<br />
    {/categories}
{/exp:channel:entries}

This will give you an output like:

Toys [0, 1]       // Parent Category
Children [1, 2]   // Child Category

Armed with this information, you can rework your conditional breadcrumbs to deal with products classified in two or more categories:

{exp:channel:entries channel="toys"}
    {categories limit="2"}    
        {if parent_id == "0"}
            <!-- Show the Parent Category -->
            <li><a href="{path=toys/list}">{category_name}</a></li>
        {/if}

        {if parent_id != "0"}
            <!-- Show the Child Category -->
            <li><a href="{path=toys/list}">{category_name}</a></li>
        {/if}
    {/categories}
{/exp:channel:entries}


Can you have an AND statement in your conditionals? Something like {if parent_id == "26" && category_id == "40"}

Just a guess. That means you're doing one check, and both conditions have to be true.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜