表达式引擎 - 面包屑问题!
好的,我已经使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
出于调试目的,理解和“可视化”您正在处理的数据的结构通常很有帮助。
要了解您正在尝试寻找面包屑路径的类别 ,使用以下代码输出每个类别的
parent_id
和category_id
:这将为您提供如下输出:
有了这些信息,您可以重新设计条件面包屑以处理分为两个或多个类别的产品:
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
andcategory_id
:This will give you an output like:
Armed with this information, you can rework your conditional breadcrumbs to deal with products classified in two or more categories:
条件语句中可以有 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.