0

嗨,我试图通过根据产品名称、价格和类别创建自动 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);

但是,如果“特价”(销售价格)小于“价格”(正常价格),我希望包含文本“特价” - 即如果有“特价”价格的值。

提前致谢!

4

1 回答 1

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');

为了便于阅读,我将其拆分(三元运算符太多了!)并添加." SALE"到第 4 行。


如果您不想SALE在价格之后立即写,您可以简单地添加

$sale = $this->data['special'] ? "SALE" : "";

并附加到$sale任何你想要的地方。

于 2013-03-12T13:18:16.187 回答