2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > opencart seo优化_OpenCart商品与目录页标题SEO优化

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

时间:2024-02-13 23:26:20

相关推荐

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”。

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

(责任编辑:最模板)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。