在永久链接页面上使用 ExpressionEngine 的 {category_name}?
我需要帮助解决使用 ExpressionEngine 2 构建的网站上遇到的一个简单问题。
我有一个使用 {title_permalink='product/view'}
链接到“视图”页面的类别。在此页面上,我想创建一个链接以将用户“返回”到该类别(例如返回玩具)。我如何创建这个链接?
例如,我本以为这段代码会起作用:
{exp:channel:category_heading channel="project"}
<p class="pfloatRight"><a href="#"> Back to {category_name}</a></p>
{/exp:channel:category_heading}
但它不起作用,因为 ExpressionEngine 不知道该条目属于哪个类别。我尝试启用 lated_categories_mode 但这没有帮助。
有什么想法吗?我知道这是一个简单的修复,我只是不习惯使用类别。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不介意输出条目分配到的所有类别,您可以从产品视图永久链接页面提供“返回类别”的链接。
将以下代码放入您的
exp:channel:entries
标记循环中:这将输出类似以下内容:
您会注意到我将“返回”文本放置在
{categories}
变量对,因此不会重复并使用退格参数删除逗号最后一类。明显的缺点是,如果为一个条目分配了多个类别,则用户可能会难以记住他们是从哪个类别导航的。
我认为大多数人习惯于使用浏览器的后退按钮而不是任何页面上的链接,因此尝试确定他们来自的实际类别可能不会带来什么投资回报。
然而,即使这些“返回类别”链接不一定对用户有用,但它们确实为那些可能从搜索结果登陆产品页面并希望查看同一类别中的更多商品的人提供了 SEO 好处。
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:Which would output something like:
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.
如果您只为产品分配了一个类别,则可以在
channel:entries
循环中执行此操作:如果您为每个产品使用多个类别,则必须使用附加 -为您存储 URL 历史记录的(或自定义代码)(例如 这个) 并以这种方式检索上次访问的页面。
If you only have one category assigned to the product, you can do this within your
channel:entries
loop:If you're using multiple categories per-product, then you'd have to use an add-on (or custom code) that stores the URL history for you (like this one) and retrieve the last-visited page that way.
您的代码看起来应该可以工作。您尝试从哪个 URL 执行此代码?
Your code looks like it should work. What's the URL you're trying to execute this code from?