在Magento中为类别设置规范标签 [英] Setting canonical tags for categories in Magento

查看:62
本文介绍了在Magento中为类别设置规范标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能吗,或者是否可以添加一些代码,以便我可以在 Magento 中为类别设置不同的规范 URL?我可以为产品设置好.

Is this possible, or is there some code that can be added so I can set a different canonical URL for categories in Magento? I can set for products fine.

推荐答案

开箱即用,对此我没有任何了解.您将需要开发或构建自己的方法.

Out of the box there is nothing for this that I am aware of. You will need to develop or build your own method of doing this.

当您在类别页面上时(您可能会在catalog_Category_view块中),您将需要在layout.xml文件中创建一个条目,以便在页面的顶部放置一个附加模板.您可能还需要一个视图文件以及一个Block对象来获取要使用的URL(从技术上讲,您可以将其放入视图文件中,但使用Block对象则更像是"Magento").

You will need to create an entry in a layout.xml file to put an additional template in the head section of the page when you are on a category page (this would likely be in a catalog_Category_view block). You would also probably need a view file as well as a Block object to fetch the URL you want to use (technically you could put that in the view file, but having the block object is more "Magento").

您的layout.xml块看起来像这样

Your layout.xml block would look something like this

<catalog_category_view>
    <reference name="head">
        <block type="canonical/canonical" name="head_url" as="head_url" template="ocaff/canonical/head.phtml" />
    </reference>
</catalog_category_view>

此块引用一个head.phtml文件.该文件将包含:

This block references a head.phtml file. That file would contain:

<link rel="canonical" href="<?php echo $this->getCanonicalUrl() ?>" />

这将回调具有功能为getCanonicalUrl()的块对象.在此功能中,您将找到并确定您想要的规范.您最有可能希望将其用作URL密钥,但是您可能还需要考虑其他逻辑.

This calls back to a block object that has a function called getCanonicalUrl(). In this function you will find and determine what you want the canonical to be. Most likely you want this to be the URL key, but you may have other logic in mind there.

这篇关于在Magento中为类别设置规范标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆