dsoihsnz85757 2014-03-12 08:11
浏览 41

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

I’ve created a new OpenCart 1.5.6 store – http://www.example.eu - however, a lot of its pages are identical (in terms of text context) to pages in an old store which is still running – http://www.example.co.uk

With both sites indexed, I’d like to reference all identical pages at the old site by including canonical tags in the new site:

e.g. The “About Us” page at http://www.example.eu/about-us should ideally have something like that in its head section:

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

e.g. The “Delivery” page at http://www.example.eu/delivery should ideally have something like that in its head section:

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

I’m aware how that can be achieved in theory, but cannot apply it in practice. Additionally, while I’m mostly concerned about all the Information-type pages, ideally I’d love to be able to specify the exact pages that will have the canonical tag, something like:

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条回答 默认 最新

  • doushi1960 2014-07-14 05:28
    关注

    The best way to achieve this is to modify your Document class, set your canonical in your controller, then render it in the header controller.

    Edit system/library/document.php

    add:

    private $canonical; to your class variables up top.

    Then add the following methods:

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

    In your header controller add:

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

    Then you can set your canonical dynamically in the header controller:

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

    Or you can set it manually in your controllers using the setCanonical method.

    评论

报告相同问题?

悬赏问题

  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类