我有一个网站,想要在头部添加一些标签以便于SEO。H1标题必须包含制造商名称(品牌)和产品代码(型号)。
问题是我不确定如何将这些变量放入控制器文件中,以便于在模板文件中调用它们。
有什么想法吗?:)
catalog/controller/product/product.php
并更改标题。 它已设置为
$this->document->setTitle($product_info['name']);
所以你只需要在那里添加厂商的名称,例如
$this->document->setTitle($product_info['name'] . ' ' . $product_info['manufacturer']);
完成了!将此代码添加到controller/common/header.php文件中
if (isset($this->request->get['product_id'])) {
$product_id = $this->request->get['product_id'];
} else {
$product_id = 0;
}
$this->load->model('catalog/product');
$product_info = $this->model_catalog_product->getProduct($product_id);
$this->data['product_info'] = $product_info;
if ($product_info) {
$this->data['manufacturer'] = $product_info['manufacturer'];
$this->data['model'] = $product_info['model'];
}
将此内容添加到 theme/default/template/common/header.tpl 文件中
<?php echo $product_info['manufacturer']; ?> <?php echo $product_info['model']; ?>