I need help with a simple issue I'm having on a site built with ExpressionEngine 2.
I have a category which links to a "view" page using {title_permalink='product/view'}
. On this page, I want to create a link to take the users "back" to the category (e.g. Back to Toys). How do I create this link?
For example, I would've thought this code would work:
{exp:channel:category_heading channel="project"}
<p class="pfloatRight"><a href="#"> Back to {category_name}</a></p>
{/exp:channel:category_heading}
But it doesn't as ExpressionEngine doesn't know which category the entry is in. I tried enabling related_categories_mode but it didn't help.
Any ideas? I know this is a simple fix, I'm just not used to working with categories.
If you don't mind outputting all the categories an entry is assigned to, you can offer a link "back to a category" from your product view permalink page.
Put the following code within your exp:channel:entries
tag loop:
<p class="pfloatRight">
Back to
{categories backspace="2"}
<a href="{path="product/index"}">{category_name}</a>,
{/categories}
</p>
Which would output something like:
<p class="pfloatRight">
Back to <a href="#">Category Name</a>, <a href="#">Category Name</a>
</p>
You'll notice I placed the "Back to" text outside the {categories}
variable pair so it doesn't get repeated and used the backspace parameter to remove the comma from the last category.
The apparent downside is that if there's more than one category assigned to an entry, it may be confusing for the user to remember which category they navigated from.
I'd argue that most people are accustomed to using their browser's Back button rather than any on-page links, so trying to determine the actual category they came from may provide little return on investment.
However, even if these "Back to Category" links aren't necessarily useful to users, they do provide SEO benefits for people who may land on a product page from a search result and want to see more items in the same category.