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'); 
相關問題