1

我得到了像我在我的PHP网站中使用多个主题的情况,并且还整合了一个WordPress博客。如何在wordpress中以编程方式设置主题?

例如: 这是我的网站网址:http://example.com

,我想通过传递查询字符串的URL相似的转换主题: http://example.com?mytheme=red_theme http://example.com?mytheme=blue_theme

目前在WordPress我激活的主题是像“blue_theme”, 和我的WordPress博客网址是这样的: http://example.com/blog?mytheme=red_theme

e。 g .:'red_theme'应该像预览一样显示。

否则,如果我去通过这个网址: http://example.com/blog

然后默认主题(blue_theme)应显示。

我可以在核心PHP中调整它,但我不知道如何处理wordpress。

请任何人都可以帮忙做这个东西。 请更多地指出你的答案,因为我是wordpress的新手。

+2

['switch_theme()'](https://codex.wordpress.org/Function_Reference/switch_theme)... – rnevius

+0

你是否已经找了现有的插件这里:https://wordpress.org/plugins/tags/theme-switcher? – dhh

+0

嗨mevius,谢谢你提醒这个WordPress的功能,我也试过使用该功能,它工作正常,但这个功能是永久激活主题,我正在寻找它应该保持基于查询字符串url临时主题。否则默认主题先前被激活... –

回答

2

在WORDPRESS中,您可以设置主题以编程方式,基于设备,就像手机上的不同主题和桌面上的不同主题。写下面的代码在默认主题的functions.php

function use_mobile_theme() { 
    // Chech device is mobile or not 
    if(wp_is_mobile()){ 
     return 'theme19388'; // set theme name here, which you want to open on mobile 
    } 
    else { 
     return 'milano'; // set theme name here, which you want to open on other devices, like desktop 
    } 
} 

add_filter('stylesheet', 'use_mobile_theme'); 
add_filter('template', 'use_mobile_theme'); 
相关问题