Post
by Arlto » Sat Feb 11, 2012 9:34 pm
This is work for me OC 1.5.1 orginal From GuruBob / change this for 1.5.1 – from misscaprice
The settings template (admin/view/template/setting/setting.tpl):
<tr>
<td><?php echo $entry_meta_keywords; ?></td>
<td><textarea name="config_meta_keywords" cols="40" rows="5"><?php echo $config_meta_keywords; ?></textarea></td>
</tr>
--------------------------------------------------------------------
Meta keywords for OpenCart – from GuruBob
OpenCart out of the box does not support meta keywords throughout the system. This is relatively easy to add, but you will need to edit each controller to enable this.
In this particular post we’ll take a look at adding support for meta keywords on the OpenCart home page. There is support already for a meta description and this can be configured in the back end of OpenCart under System » Settings » Store » Meta Tag Description.
Our aim will be to add another field beneath that called “Meta Tag Keywords” and have this reflect in the source of the homepage.
There are two parts to this: adding support for editing and storing the meta keywords in the admin, and adding the code to the front of the website so that the value will be used.
In the admin:
There are three things you’ll need to do to provide support for this in the admin.
Edit the setting controller to get the value from the database.
Edit the setting language file to provide labels for the form.
Edit the settings template to provide the HTML for the form.
The Controller
The admin controller we want is found in the admin/controller/setting/setting.php file. Depending on which version of OpenCart you have, at about line 47 you’ll find a reference to the entry_meta_description. Simply copy that line and replace the text entry_meta_description with entry_meta_keywords.
$this->data['entry_meta_keywords'] = $this->language->get('entry_meta_keywords');
Also, a bit later in the file (search for config_meta_description) we want to add a section which will take care of collecting up the posted results of the form. Use the other sections as a guide:
if (isset($this->request->post['config_meta_keywords'])) {
$this->data['config_meta_keywords'] = $this->request->post['config_meta_keywords'];
} else {
$this->data['config_meta_keywords'] = $this->config->get('config_meta_keywords');
}
The language file
The language file changes are very simple. Open the file admin/language/english/setting/setting.php and add a line beneath the entry_meta_description line that says:
$_['entry_meta_keywords'] = 'Meta Tag Keywords:';
The settings template (view)
Oopen the file admin/view/template/setting/setting.tpl, find the config_meta_description and paste this after it. Note that it’s a HTML table so you’ll paste this after the closing </tr> tag of the table row for the meta description:
<tr>
<td><?php echo $entry_meta_keywords; ?></td>
<td><input type="text" name="config_meta_keywords" value="<?php echo $config_meta_keywords; ?>" />
<?php if ($error_entry_meta_keywords) { ?>
<span class="error"><?php echo $error_entry_meta_keywords; ?></span>
<?php } ?></td>
</tr>
In the front end:
The front end changes are very straightforward. We need to make changes to the header template and the home controller.
The header template
Open the file catalog/view/theme/default/template/common/header.tpl and add the following code after the definition of the description meta tag:
<?php if ($keywords) { ?>
<meta name="keywords" content="<?php echo $keywords; ?>" />
<?php } ?>
The home controller
Finally, open the home controller (catalog/controller/common/home.php) and find the reference to the config_meta_description. Simply copy that line and change it for the keywords:
$this->document->keywords = $this->config->get('config_meta_keywords');
Complete
Now you’re done – you should be able to update the keywords in the System » Settings » Store » Meta Tag Keywords and see these in the HTML source.
In addition to this, you’ve also made a key change to the template so that in any controller you can set $this->document->keywords to whatever you like and those keywords will show in the HTML source.
http://www.arlto.com Online prodavnica dodatne opreme za mobilne telefone