繁体   English   中英

如何在Prestashop中将类别页面设置为主页

[英]How to Set Category Page as Home Page in Prestashop

我有http://example.com/index.php作为我的主页。 我的类别页面网址是http://example.com/index.php?id_category=10&controller=category

现在,我需要将我的主页重定向到Category Page。 我尝试在首选项> SEO和URL的>设置商店URL>基本URI作为index.php?id_category = 10&controller = category

现在,该页面正在重定向到我的类别URL,但该页面未打开。 URL显示如下http://example.com/index.php?id_category=10&controller=category/index.php

你这样做是错误的。 做到如下:

A)简单但不推荐方式:

1)打开Controllers / IndexController.php

2)修改函数initContent如下:

public function initContent()
{

   parent::initContent();
   Tools::redirect('index.php?id_category=10&controller=category');
   $this->context->smarty->assign('HOOK_HOME', Hook::exec('displayHome'));
   $this->setTemplate(_PS_THEME_DIR_.'index.tpl');

}

B)推荐方式:

1)复制Controllers / IndexController.php以覆盖/控制器/文件夹2)打开复制的文件并进行如下编辑:

class IndexController extends IndexControllerCore 
{

    public function initContent()
    {
       Tools::redirect('index.php?id_category=10&controller=category');

    }
}

3)保存文件并转到缓存文件夹。 找到class_index.php ,如果它在那里然后删除它。 然后检查网站是否正常工作。

备注:

1)上面的代码是给你的想法,它可能会或可能不会工作。 请根据您的需要进行调整。

2)在最新版本的Prestashop中,所有类都在class_index.php文件中编制索引。 因此,如果您对控制器或类进行了任何覆盖,则在删除该文件之前它可能无效。 当向服务器发出新请求时,PS会自动为您重新生成该文件。

希望这会有所帮助。

这是我的方式:

  1. 创建文件覆盖/ controllers / front / IndexController.php
  2. 写作:
class IndexControllerCore extends FrontController {
      public function initContent()
        {
          Tools::redirect('index.php?id_category=3&controller=category');
        }
      }
  1. 保存
  2. 删除文件缓存/ class_index.php
  3. 利润!

暂无
暂无

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

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