A-A+

给Opencart增加功能:OpenCart分类增加meta title

2012年09月13日 灵犀一指 给Opencart增加功能:OpenCart分类增加meta title已关闭评论 阅读 1,370 人 次

opencart中分类页面meta title默认显示的是分类名称,而没有自定义的meta title,官方给出的解释是meta title在google 已经没有作用的所以省略了。但是我们还是习惯自定义的meta title,下面教大家怎么样添加meta title。

修改后台文件

1、修改admin\controller\catalog\category.php,查找

[php]
$this->data['entry_meta_keyword'] = $this->language->get('entry_meta_keyword');
[/php]

在其上添加

[php]
$this->data['entry_meta_title'] = $this->language->get('entry_meta_title');
[/php]

2、修改admin\model\catalog\category.php,查找(大约12行)

[php]
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']) . "'");
}
[/php]

修改为

[php]
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']) . "'");
}
[/php]

继续查找(大约46行)

[php]
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']) . "'");
}
[/php]

修改为

[php]
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']) . "'");
}
[/php]

继续查找(大约142行)

[php]
'meta_keyword' => $result['meta_keyword'],
[/php]

在其上添加

[php]
'meta_title' => $result['meta_title'],
[/php]

3、修改admin\language\english\catalog\category.php,查找

[php]
$_['entry_meta_keyword'] = 'Meta Tag Keywords:';
[/php]

在其上添加

[php]
$_['entry_meta_title'] = 'Meta Tag Title:';
[/php]

4、修改admin\view\template\catalog\category_form.tpl,查找(大约第35行)

[php]
<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>
[/php]

在其上添加

[php]
<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>
[/php]

修改前台文件

修改catalog\controller\product\category.php,查找(大约第75行)

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

修改为

[php]
$this->document->setTitle(empty($category_info['meta_title'])?$category_info['name']:$category_info['meta_title']);
[/php]

修改数据库

数据库 category_description表中增加meta_title字段,phpmyadmin中运行以下sql语句

[php]
ALTER TABLE `category_description` ADD `meta_title` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL ;
[/php]

评论已关闭!