首页 » Linux » OpenCart » 阅读文章
OpenCart分类增加meta title
opencart中分类页面meta title默认显示的是分类名称,而没有自定义的meta title,官方给出的解释是meta title在google 已经没有作用的所以省略了。但是我们还是习惯自定义的meta title,下面教大家怎么样添加meta title。
修改后台文件
1、修改admin\controller\catalog\category.php,查找
$this->data['entry_meta_keyword'] = $this->language->get('entry_meta_keyword');
在其上添加
$this->data['entry_meta_title'] = $this->language->get('entry_meta_title');
2、修改admin\model\catalog\category.php,查找(大约12行)
foreach ($data['category_description'] as $language_id => $value) { $this->db->query("INSERT INTO " . DB_PREFIX . "category_description SET category_id = '" . (int)$category_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "'"); }
修改为
foreach ($data['category_description'] as $language_id => $value) { $this->db->query("INSERT INTO " . DB_PREFIX . "category_description SET category_id = '" . (int)$category_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "',meta_title = '" . $this->db->escape($value['meta_title']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "'"); }
继续查找(大约46行)
foreach ($data['category_description'] as $language_id => $value) { $this->db->query("INSERT INTO " . DB_PREFIX . "category_description SET category_id = '" . (int)$category_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "'"); }
修改为
foreach ($data['category_description'] as $language_id => $value) { $this->db->query("INSERT INTO " . DB_PREFIX . "category_description SET category_id = '" . (int)$category_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "',meta_title = '" . $this->db->escape($value['meta_title']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "'"); }
继续查找(大约142行)
'meta_keyword' => $result['meta_keyword'],
在其上添加
'meta_title' => $result['meta_title'],
3、修改admin\language\english\catalog\category.php,查找
$_['entry_meta_keyword'] = 'Meta Tag Keywords:';
在其上添加
$_['entry_meta_title'] = 'Meta Tag Title:';
4、修改admin\view\template\catalog\category_form.tpl,查找(大约第35行)
<tr> <td><?php echo $entry_meta_description; ?></td> <td><textarea name="category_description[<?php echo $language['language_id']; ?>][meta_description]" cols="40" rows="5"><?php echo isset($category_description[$language['language_id']]) ? $category_description[$language['language_id']]['meta_description'] : ''; ?></textarea></td> </tr>
在其上添加
<tr> <td><?php echo $entry_meta_title; ?></td> <td><textarea name="category_description[<?php echo $language['language_id']; ?>][meta_title]" cols="40" rows="5"><?php echo isset($category_description[$language['language_id']]) ? $category_description[$language['language_id']]['meta_title'] : ''; ?></textarea></td> </tr>
修改前台文件
修改catalog\controller\product\category.php,查找(大约第75行)
$this->document->setTitle($category_info['name']);
修改为
$this->document->setTitle(empty($category_info['meta_title'])?$category_info['name']:$category_info['meta_title']);
修改数据库
数据库 category_description表中增加meta_title字段,phpmyadmin中运行以下sql语句
ALTER TABLE `category_description` ADD `meta_title` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL ;
声明: 本文由Ezencart原创,转载请保留链接:OpenCart分类增加meta title
评论 共0条 (RSS 2.0) 发表评论