opencart seo优化_OpenCart商品与目录页标题SEO优化

OpenCart 在 SEO 方面不是很尽如人意,很难定制标题 Title 标签或者 META DATA,而这些对于搜索引擎友好又是非常重要的。现在是有OpenCart插件可以帮助做 OpenCart SEO,但在这里我们要修改代码实现!

1 目录页

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

桌面电脑

PC

Mac

笔记本电脑

Macs

Windows

我们要的效果是这样:当点击 桌面电脑 - Mac 目录时, 标题变成:Mac - 桌面电脑 - 店名。找到这个文件 catalog/controller/product/category.php,找到下面的代码:

if ($category_info) {

$this->document->setTitle($category_info['meta_title']);

要添加父目录名称,我们需要改成:

if ($category_info) {

// $this->document->setTitle($category_info['meta_title']);

foreach ( $data['breadcrumbs'] as $key => $value ){

$parentCategorys[$key] = $data['breadcrumbs'][$key]['text'];

}

array_shift($parentCategorys); // 删除第一个元素, 也就是首页

$parentCategorys = array_reverse( $parentCategorys ); // 反转数组

$parentCategory = implode( ' - ', $parentCategorys );           // 数组转换成字符串

$newTitle = $category_info['meta_title'];                       // 当前分类名

if ($parentCategory) {

$newTitle .= ' - ' . ucwords($parentCategory);          // 首字母大写

}

$newTitle .= ' - ' . $this->config->get('config_name');         // 加上商店名称

$titleLength = strlen($newTitle);

if ($titleLength > 70) {

$newTitle = substr($newTitle, 0, 67);

$newTitle = $newTitle . "...";

}

$this->document->setTitle($newTitle);

也就是注释掉原来显示“meta_title”的一行,然后加上一系列代码实现分目录标题的显示,其中用到了面包屑导航的内容。

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

产品页

产品页的 Title 本来是不包含点名的,所以我们需要在后面加上店名。打开代码页文件:catalog/controller/product/product.php,找到下面这行

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

改成:

$this->document->setTitle($product_info['meta_title'] . ' - ' . $this->config->get('config_name'));

这样,进入 MacBook 商品页,标题变成 “MacBook - Your store”。

当然,页可以给标题加入其它值,例如厂家:

$this->document->setTitle($product_info['meta_title'] . ' - ' . $product_info['manufacturer'] . ' - ' . $this->config->get('config_name'));

这样,进入 MacBook 商品页,标题变成 “MacBook - Apple - Your store”。

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

(责任编辑:最模板)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值