Default OpenCart theme doesn't provide means to do this because header.tpl outputs <body> tag wihout any classes, making the previous task impossible to accomplish.
But, cry no more! After making the changes described below you will have <body> tag with various classes appended, all in relation to the page being viewed (product pages, category pages, account pages, information pages, current language, SEO and nonSEO URLs, everything is covered).
So, here is how to make it work
Open catalog/controller/common/header.php
Find
Code: Select all
$this->data['title'] = $this->document->getTitle();
Code: Select all
// start body_class code
$current_path = $this->request->get;
if (empty($current_path) || $current_path['route'] == 'common/home') {
$body_class = 'home';
}
else {
$body_class = explode('/', str_replace('product/', '', $current_path['route']));
unset($current_path['route']);
if (isset($current_path['_route_'])) {
$body_class = array_merge($body_class, explode('/', str_replace('-', '_', $current_path['_route_'])));
unset($current_path['_route_']);
}
foreach ($current_path as $key => $value) {
$body_class[] = $key . "_" . $value;
}
$body_class = 'page_' . implode(" page_", array_unique($body_class));
}
$body_class .= ' lang_' . $this->language->get('code');
$this->data['body_class'] = $body_class;
// end body_class code
catalog/view/theme/YOUR_THEME_NAME/template/common/header.tpl
Replace
Code: Select all
<body>
Code: Select all
<body class="<?php echo $body_class; ?>">
Theme ahead, OpenCarters