企业级电子商务与供应链解决方案供应商.
联系我们

+86-13006619568

info@cnopencart.com

深圳,苏州,成都,上海,杭州

扫二维码加微信
wechat

深圳,苏州

+86-16606168892

Top

商品与目录页的标题搜索优化-OpenCart SEO

商品与目录页的标题搜索优化-OpenCart SEO

OpenCart 在 SEO 方面不是很尽如人意, 你很难定制标题 Title 标签或者 META DATA, 这些对于搜索引擎友好是非常重要的.

现在是有OpenCart插件可以帮助做 OpenCart SEO, 但在这里, 我们要 DIY !

以官网 demo 店里的商品目录为例:

桌面电脑

  • PC
  • Mac

笔记本电脑

  • Macs
  • Windows

我们要的效果是这样: 当点击 桌面电脑 - Mac 目录时, 标题变成: Mac 桌面电脑 - 店名.

找到这个文件 catalog/controller/product/category.php

找到下面的代码:

------- 源码 -------

if ($category_info) {
$this->document->setTitle($category_info['name']);// 设置标题, 这里仅以目录名称为标题
$this->document->setDescription($category_info['meta_description']);//描述标签
$this->document->setKeywords($category_info['meta_keyword']);//关键字

------- 源码 -------

要添加父目录名称, 如桌面电脑, 我们需要这样改:

--------- 父目录名称 开始 ----------

if ($category_info) {
$parentIDValue = $this->request->get['_route_'];//父目录ID,格式是XML,下面需是截取出ID
$parentIDPos = strpos($parentIDValue, "/");//父目录ID位置
$parentCategory = substr($parentIDValue, 0, $parentIDPos);//截取出目录ID

$newTitle = $category_info['name']." ".$parentCategory." - " . $this->config->get("store_name");//新的标题
$titleLength = strlen($newTitle);
if($titleLength > 70){
$newTitle = substr($newTitle, 0, 67);
$newTitle = $newTitle."...";
}

$this->document->setTitle($newTitle);
$this->document->setDescription($category_info['meta_description']);
$this->document->setKeywords($category_info['meta_keyword']);

--------- 父目录名称 结束 ----------

搞定目录也了, 接下来的商品页就轻车熟路了.

找到代码页: catalog/controller/product/product.php

$this->document->setTitle($product_info['name']);

改成:

$this->document->setTitle($product_info['name']." - " . $this->config->get("store_name"));

我们也可以给标题加入其它值, 例如厂家.

$this->document->setTitle($product_info['name']." - ".$product_info['manufacturer']." - " . $this->config->get("store_name"));

如进入 MacBook 商品页, 标题变成 "MacBook - Apple - Your store".

至此简单地完成了对商品和目录页的搜索优化.

其它便可随意扩展了, 例如增加 information 页的 title, 自动赋值 meta keyword, 内链 等等, 再做成 vqMod 插件. Nice ! ! !