简体   繁体   English

opencart中类别的自定义标题图像

[英]Custom header image for category in opencart

I have 4 main categories in an opencart site. 我在opencart网站中有4个主要类别。

I want to have a different header image for the 4 separate categories. 我想为4个单独的类别使用不同的标题图像。 How can I get the current category name and put an if statement to select the image for the header? 如何获取当前类别名称并放置if语句以选择标题的图像?

Current header image code: 当前标题图片代码:

<div id="headerWrapper">
<div id="header">
    <div class="div1">
        <div class="div2">
        <?php if ($logo) { ?>
        <a href="<?php echo str_replace('&', '&amp;', $home); ?>"><img src="<?php echo $logo; ?>" title="<?php echo $store; ?>" alt="<?php echo $store; ?>" /></a>
        <?php } ?>
        </div>        
    </div>
</div>

You will need to work out if the path is set and the route is product/category to begin with, to check if you are even on a category page. 您需要确定是否设置了路径,并且路线首先是产品/类别,以检查您是否在类别页面上。 Then you will need to use that information in a switch really (rather than a large if else listing). 然后,您将需要在交换机中真正使用该信息(而不是大量列出的信息)。 Can you give more detail on what it is you are wanting to change in the code above? 您能否在上面的代码中提供您想要更改的详细信息? Is it the logo or are you wanting to add a class to the header that you can then use to style via your stylesheet 是徽标还是您想要向标题添加类,然后可以通过样式表使用该类进行样式设置

To find out if you are in the category, use this in the index() method in catalog/controller/common/header.php 要确定您是否在类别中,请在catalog/controller/common/header.php中的index()方法中使用它

$get = $this->request->get;
$this->data['cat_id'] = false;
$this->data['cat_name'] = '';
if(!empty($get['route']) && $get['route'] == 'product/category' && !empty($get['path'])) {

    $cats = explode('_', $get['path']);
    $cat_id = array_pop($cats);
    $cat_id = (int) $cat_id;

    if($cat_id) {
        $this->load->model('catalog/category');
        $result = $this->model_catalog_category->getCategory($cat_id);
        $this->data['cat_id'] = $cat_id;
        $this->data['cat_name'] = $result['name'];
    }
}

This will give you two variables to use in your template's common/header.tpl file 这将为您提供两个在模板的common / header.tpl文件中使用的变量

$cat_id and $cat_name $cat_id$cat_name

$cat_id will be the current category id, or false if it's not a category page $cat_id将是当前类别ID,如果不是类别页面,则为false

$cat_name will have the current category name if one exists, or an empty string if it doesn't $cat_name将具有当前类别名称(如果存在),如果没有则为空字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM