如何获取当前类别ID - OpenCart

时间:2013-02-04 08:42:00

标签: php opencart

我想在标题中添加 - if语句:

<?php if (category = 17) { ?>
<meta name="description" content="category 17 description" />
<?php } ?>

<?php if (category = 18) { ?>
<meta name="description" content="category 18 description" />
<?php } ?>

如何获取当前类别ID

5 个答案:

答案 0 :(得分:3)

将此代码放在标题中的代码

之前
$category = empty($this->request->get['path']) ? 0 : (int) array_pop(explode('_', $this->request->get['path']));

然后在问题中使用$category代替category

答案 1 :(得分:2)

如果您只需要类别ID,则它是url参数“path”。 因此,在header.tpl中访问类别ID的最佳方法是

<?php if(isset($_GET['category_id'])){
  if ($_GET['path'] = 17) { ?>
<meta name="description" content="category 17 description" />
<?php } ?>

<?php if ($_GET['path'] = 18) { ?>
 <meta name="description" content="category 18 description" />
<?php } 
}  

答案 2 :(得分:0)

您想从哪里获取类别ID?

是否在网址中?

然后你必须使用全局$ _GET变量。

如果网址是

example.com/index.php?category=2

您可以使用

获取参数
$category= $_GET["category"]

答案 3 :(得分:0)

我想这样做的最佳方法是在meta description控制器中添加category,就像这样:

$this->document->addMeta($category_info['description']);

只需编辑您的/catalog/controller/product/category.php控制器文件。

答案 4 :(得分:0)

if(isset($this->request->get['path'])) {
    $path = $this->request->get['path'];
    $cats = explode('_', $path);
    $cat_id = $cats[count($cats) - 1];
}
echo $cat_id;

来源:http://chandreshrana.blogspot.in/2014/07/get-current-category-in-opencart.html

相关问题