如何将规范标签添加到OpenCart页面?

时间:2014-03-12 08:11:33

标签: php seo opencart canonical-link

我已经创建了一个新的OpenCart 1.5.6商店 - http://www.example.eu - 然而,它的很多页面(在文本上下文中)与旧商店中仍在运行的页面相同 - {{ 3}}

如果两个网站都已编入索引,我想通过在新网站中添加规范标记来引用旧网站上的所有相同网页:

例如 http://www.example.co.uk上的“关于我们”页面理想情况下应该在其主题部分中有类似内容:

<link rel="canonical" href="http://www.example.co.uk/delivery"/>

例如 http://www.example.eu/about-us处的“投放”页面理想情况下应该在其主题部分中显示类似内容:

<link rel="canonical" href="http://www.example.co.uk/delivery"/>

我知道如何在理论上实现这一点,但不能在实践中应用它。此外,虽然我主要关注所有信息类型的页面,但理想情况下我希望能够指定具有规范标签的确切页面,例如:

If (this page is About-Us OR Delivery OR … OR … OR … OR …)
{
Include Canonical Tag of the type <link rel="canonical" href="http://www.example.co.uk/xxxxxxxx"/> , 
where xxxxxxx changes accordingly, depending on the page.
}
Else
{
Don’t include Canonical Tag
}

1 个答案:

答案 0 :(得分:0)

实现此目的的最佳方法是修改Document类,在控制器中设置规范,然后在标题控制器中呈现它。

编辑system / library / document.php

添加:

private $canonical;将您的班级变量排在最前面。

然后添加以下方法:

public function setCanonical($url) {
    $this->canonical = $url;    
}

public function getCanonical() {
    return $this->canonical;
}

在标头控制器中添加:

$this->data['canonical'] = $this->document->getCanonical();

然后,您可以在标题控制器中动态设置规范:

if (isset($this->request->get['_route_'])):
    $canonical_route = $this->request->get['_route_'];
else:
    $canonical_route = '';
endif;

$this->document->setCanonical($this->data['base'] . $canonical_route);

或者您可以使用setCanonical方法在控制器中手动设置它。

相关问题