表达式引擎 - 面包屑问题!

发布于 2024-11-19 07:55:19 字数 1295 浏览 3 评论 0原文

好的,我已经使用 IF 段和 IF Category_id 语句设置了面包屑试验。原因是因为我有不同的产品链接到 2-3 个类别等...

我已经完成了整个试验并且一切正常(尽管有很多编码!)

但是,我遇到了一个大问题,我已经尝试了几个小时来纠正它,但不能,基本上这个类别是在 2 个父母和 2 个孩子类别中,在一个类别组下......所有其他人只有一个父母和一个孩子,所以我的代码工作正常。

我已经尝试了一切,但还是出现了

<块引用>

玩具>>本10>>儿童>>本10

它重复了类别和父级,因为条目位于一组中的这两个类别中...所以我尝试在主 if 语句之外创建两个单独的 if 语句,如下所示:

我的代码是:

{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}

我会假设定义特定的父级和猫 ID,这只会显示一个...

有什么解决方案吗?

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 have 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抱猫软卧 2024-11-26 07:55:19

出于调试目的,理解和“可视化”您正在处理的数据的结构通常很有帮助。

要了解您正在尝试寻找面包屑路径的类别 ,使用以下代码输出每个类别的 parent_idcategory_id

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

这将为您提供如下输出:

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

有了这些信息,您可以重新设计条件面包屑以处理分为两个或多个类别的产品

{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}

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}
时常饿 2024-11-26 07:55:19

条件语句中可以有 AND 语句吗?
像这样的东西
{如果parent_id == "26" && category_id == "40"}

只是一个猜测。这意味着您正在执行一项检查,并且两个条件都必须为真。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文