Breadcrumb problem in Expression Engine
I am having a small issue in expression engine, I have created a breadcrumb snippet. I have created it using {if segment_} coding.
So I created an if rule for each of the pages (it's n开发者_运维问答ot a huge site) however I am having a problem with one of the breadcrumb trials. I have numerous categories with a product view page, on this product view page I can't seem to place the category in the breadcrumb. Placing the category in the actual category page is no problem, i've used:
{if segment_4 == "toys"}<li><a href="index.php/product/category/toys">Toys</a></li>{/if}
However on the permalink page I can't do this as there are no toys in the url.
I know this is an easy fix, i'm just not very familiar with categories on expression engine.
This is a tricky question, because an entry (product) can be assigned to more than one category.
For the sake of an example, if you are only assigning one category per product, you can use the following code for a basic breadcrumbs trail in your permalink template:
{exp:channel:entries channel="product" limit="1"}
<ul class="breadcrumbs">
<li><a href="{path='site_index'}">Home</a></li>
<li><a href="{path='product/index'}">{channel}</a></li>
{categories limit="1" channel="product"}
<li>
<a href="{path='product/index'}">{category_name}</a>
</li>
{/categories}
<li>{title}</li>
</ul>
{/exp:channel:entries}
Which would output something along the lines of:
<ul class="breadcrumbs">
<li><a href="http://localhost/index.php">Home</a></li>
<li><a href="http://localhost/index.php/product">Products</a></li>
<li><a href="http://localhost/index.php/product/category/toys">Toys</a></li>
<li>Buzz Lightyear Action Figure</li>
</ul>
Depending upon how you've setup the taxonomy of your site (single category for products vs. multiple categories) will determine if you can safely use categories in your breadcrumbs.
Since you didn't post more of your code, you may choose to implement things differently, especially if you're using an embeddd template for your breadcrumbs. However, you can extract out the necessary bits from this example to suit your environment.
In addition, you can use ExpressionEngine's URL Segment Variables, Category URL Indicator and Conditional Global Variables to add even more flexibility.
I may also mention that if you're looking for a rapid and highly customizable solution to adding breadcrumbs to your site, you might want to consider the commercial add-on Crumbly by Stephen Lewis of Experience Internet.
精彩评论