我有这个网站,我想在标题中放一些用于SEO目的。H1 必须包含制造商名称(品牌)和产品代码(型号)。
所以问题是我不确定如何将这些变量放在控制器的文件中,以便接下来可以在模板文件中调用它们。
有什么想法吗?:)
解决此问题的最佳方法是编辑产品控制器
catalog/controller/product/product.php
并更改那里的标题。它设置了
$this->document->setTitle($product_info['name']);
所以你只需要在那里预置/附加制造商名称,例如
$this->document->setTitle($product_info['name'] . ' ' . $product_info['manufacturer']);
做到了!将此代码添加到控制器/公共/标头.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'];
}
这个到主题/默认/模板/通用/标题.tpl
<?php echo $product_info['manufacturer']; ?> <?php echo $product_info['model']; ?>