简体   繁体   English

Fishpig_Wordpress Magento扩展名。 主题自定义类别

[英]Fishpig_Wordpress Magento extension. Theme a custom category

I have an installed addon for magento called Fishpig. 我为magento安装了一个名为Fishpig的插件。 It essentially runs wordpress through magento allowing both to be used on the main website. 它实际上是通过magento运行wordpress的,从而可以在主要网站上同时使用两者。 The WP install is being used for a blog, and i've the whole initial theme set up for it by altering the magento files as required. WP安装正在用于博客,并且我已经通过根据需要更改magento文件来为其设置了整个初始主题。 What i'm looking for though is a way to change the theme if i look under a certain category related to the representative for the site. 如果我在与网站代表相关的特定类别下查找,我正在寻找的是一种更改主题的方法。

Is there a way to set a different template if i were to choose the category? 如果我要选择类别,是否可以设置其他模板? Will i need to add if statements to the category WP layout file? 我是否需要在类别WP布局文件中添加if语句?

If you want to change the whole theme based on the current WordPress category (or any conditions), you would need to listen to for an event and then change the theme programmtically. 如果要基于当前的WordPress类别(或任何条件)更改整个主题,则需要收听事件,然后以编程方式更改主题。 The most general event that would work would be 'controller_action_predispatch' however if you wanted to only change the theme for WordPress category pages, you would be better suited to use 'controller_action_predispatch_wordpress_post_category_view'. 最有效的事件是'controller_action_predispatch',但是,如果您只想更改WordPress类别页面的主题,则更适合使用'controller_action_predispatch_wordpress_post_category_view'。

Attach an event observer method to the event of your choosing and then use the following code: 将事件观察器方法附加到您选择的事件,然后使用以下代码:

$_category = Mage::registry('wordpress_category');

if (!$_category) {
    return $this;
}

$_categoryId = (int)$_category->getId();

if ($_categoryId === 1) {
    Mage::getDesign()
        ->setPackageName('default')
        ->setTheme('default');
}
else if ($_categoryId === 2) {
    Mage::getDesign()
        ->setPackageName('default')
        ->setTheme('default');    
}

return $this;

You would need to modify to code to set the correct package/theme (the code below enables the default package and default theme) to match the package/theme you want to set. 您将需要修改代码以设置正确的程序包/主题(下面的代码启用默认程序包和默认主题),以匹配您要设置的程序包/主题。

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

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