Jump to content

[SOLVED] Change theme through code


Recommended Posts

How were you wanting to do this? Do you have multiple themes in your themes directory and you want to switch between them or do you want to create a single theme that has multiple themes built in to it? The current theme is specified in config/settings.inc.php:

define('_THEME_NAME_', 'prestashop');



You could try using code like the following at the top of init.php to change the theme depending on the current category:

if (isset($_GET['id_category']) AND $GET['id_category'] == 2)
   define('_THEME_NAME_', 'category2');
if (isset($_GET['id_category']) AND $GET['id_category'] == 3)
   define('_THEME_NAME_', 'category3');



This code would make category 2 read themes/category2 and category 3 read themes/category3. Any other page will display the original theme in settings.inc.php.

Let me know if this is what you want or whether you want all category themes integrated into a single Prestashop theme.

  • Like 1
Link to comment
Share on other sites

Thanks rocky, That's exact what i need. But it didn't work because the init.php is included after the config.inc.php, that is where the theme dirs and images are set, plus constants can't be redefined, so once the _THEME_NAME_ is in the settings.inc.php i can't change it anymore.

So, until now i couldn't think any solution to do that. =(
any clue?

Link to comment
Share on other sites

Can you comment out the theme name definition in config.inc.php and then use the following?

if (isset($_GET['id_category']) AND $GET['id_category'] == 2)
   define('_THEME_NAME_', 'category2');
elseif (isset($_GET['id_category']) AND $GET['id_category'] == 3)
   define('_THEME_NAME_', 'category3'); 
else
   define('_THEME_NAME_', 'default');

Link to comment
Share on other sites

Yes, but as you said, only for category pages.
I have implemented a "cookie read" to set the _THEME_NAME_ and trough produtct.php and category.php i set a cookie with right theme name. =)

Thanks.

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 months later...

the abov could be used with google website optimzer calling the URL something like www.your-shop.com/index.php?theme=1 and for a new theme variation www.your-shop.com/index.php?theme=2 and then perhaps use .htaccess for a rewrite of it to make in pretty.

Link to comment
Share on other sites

×
×
  • Create New...