How to change default home page in opencart

妖精的绣舞 提交于 2019-12-11 14:16:01

问题


I am new to opencart. I just want two main pages, one will be listing all the products(by default in opencart) and the other will describes about the company. So how can i change the default home page.

These two pages should have different headers. How can i set the route for this kind of pages.

Ya i tried as follows

created new file under common as default.tpl

In my home.tpl I used

<?php if(!isset($this->request->get['route'])){
    echo $header;
}else{
    echo $default;
}
?>

But it is not rendering default. I also created a controller under controller/common/default.php with following lines

<?php
class ControllerCommonDefault extends Controller {
    public function index() {
        $this->template = $this->config->get('config_template') . '/template/common/default.tpl';
        $this->render();
    }
}

回答1:


It would be easier to write a seperate header file... if you open catalog/controller/common/home.php you will find the following code

    $this->children = array(
        'common/column_left',
        'common/column_right',
        'common/content_top',
        'common/content_bottom',
        'common/footer',
        'common/header'
    );

you could change this to

    $this->children = array(
        'common/column_left',
        'common/column_right',
        'common/content_top',
        'common/content_bottom',
        'common/footer',
        'common/headerhome'
    );

and then open:

catalog/view/theme/default/common/home.tpl

and find the following line:

<?php echo $header; ?>

and change it to:

<?php echo $headerhome; ?>

and then copy:

catalog/controller/common/header.php

and rename it

headerhome.php

and then open

catalog/controller/common/headerhome.php

and find the following line

class ControllerCommonHeader extends Controller {

and change to:

class ControllerCommonHeaderhome extends Controller {

then find:

$this->language->load('common/header');

and change to:

$this->language->load('common/header');

then find the following code:

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/header.tpl')) {
    $this->template = $this->config->get('config_template') . '/template/common/header.tpl';
} else {
    $this->template = 'default/template/common/header.tpl';
}

and change it to:

    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/headerhome.tpl')) {
        $this->template = $this->config->get('config_template') . '/template/common/headerhome.tpl';
    } else {
        $this->template = 'default/template/common/headerhome.tpl';
    }

and then copy

catalog/view/theme/default/common/header.tpl

and rename to:

catalog/view/theme/default/common/headerhome.tpl

then copy:

catalog/language/english/common/header.php

and rename to:

catalog/language/english/common/headerhome.php

you can then edit the following file to reflect the style changes that you want:

catalog/view/theme/default/common/headerhome.tpl

you can then edit the following file to reflect the language changes that you want:

catalog/language/english/common/headerhome.php

This means that the home page will show headerhome and all other pages will show the standard header, which if you are only going to have two pages like you said earlier this solves your problem...




回答2:


$this->request->get['route']

You will get the current page path using this piece of code. Write a condition based on that in your common/header.php controller file and use separate template files.



来源:https://stackoverflow.com/questions/19764880/how-to-change-default-home-page-in-opencart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!