您好我试图通过根据产品名称,价格和价格创建自动SEO友好标题来提高我的标题。我正在这样做的类别:
$catName = isset($category_info) ? " - ".$category_info['name'] : "";
$titlePrice = $this->data['special'] ? $this->data['special'] : ($this->data['price'] ? $this->data['price'] : ($this->data['tax'] ? $this->data['tax'] : ""));
$newTitle = $product_info['name']." - ".$titlePrice.$catName." - ".$this->config->get('config_title');
$this->document->setTitle($newTitle);
但是,我最好还要包含“SALE”字样如果'特价'(促销价格)小于'价格'(正常价格) - 即如果有值'特价'价格。
提前致谢!
答案 0 :(得分:0)
如果我已了解您的需求,只需在设置SALE
价格时添加special
文字:
$catName = isset($category_info) ? " - ".$category_info['name'] : "";
$tax = $this->data['tax'] ? $this->data['tax'] : "";
$price = $this->data['price'] ? $this->data['price'] : $tax;
$titlePrice = $this->data['special'] ? $this->data['special']." SALE" : $price;
$newTitle = $product_info['name']." - ". $titlePrice . $catName. " - ".$this->config->get('config_title');
为了便于阅读,我将它拆分了(太多的三元运算符!)并在第4行添加了." SALE"
。
如果您不想在价格之后立即写SALE
,只需添加
$sale = $this->data['special'] ? "SALE" : "";
并将$sale
追加到任意位置。