[WordPress] 外掛分享: Conditional Themes

首頁外掛目錄 › Conditional Themes
50+
安裝啟用
★★★★
4.9/5 分(9 則評價)
2569 天前
最後更新
問題解決
WordPress 3.4+ v0.6 上架:2013-10-18

內容簡介

Conditional Themes 是一個用來依照特定條件切換 WordPress 主題的 API。

使用方法

寫一個額外的外掛檔案並像下面的範例一樣使用 Conditional Themes API:

add_action('plugins_loaded', 'my_conditional_themes_setup', 100);

function my_conditional_themes_setup()
{
// 如果使用者使用 Internet Explorer,則切換成 Twenty Eleven 主題。
Conditional_Themes_Manager::register('twentyeleven', function() {
global $is_IE;
return (bool) $is_IE;
});

// 如果使用者的身份是管理員,則切換成 Twenty Thirteen 主題。
Conditional_Themes_Manager::register('twentythirteen', function() {
return current_user_can('administrator');
});

// 如果使用者使用行動裝置,則切換成自訂主題。
Conditional_Themes_Manager::register('mobile', 'wp_is_mobile');
}

另一個例子,啟用永續模式。

add_action('plugins_loaded', 'my_conditional_themes_setup', 100);

function my_conditional_themes_setup()
{
// 啟用切換器的永續模式。
Conditional_Themes_Manager::set_option('persistent', true);

// 當我們處於 2016 年時,切換成 Twenty Sixteen 主題。
Conditional_Themes_Manager::register('twentysixteen', function() {
return (date('Y') == 2016);
});

// 當網站文章數超過 500 篇時,切換成 Twenty Fifteen 主題。
Conditional_Themes_Manager::register('twentyfifteen', function() {
return ((int) wp_count_posts() > 500);
});
}

注意:您可以使用 Code Snippets 外掛將程式碼片段新增到您的網站中。

貢獻

開發人員可以在 Github 儲存庫 上貢獻原始碼。

外掛標籤

開發者團隊

⬇ 下載最新版 (v0.6) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Conditional Themes」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

Conditional Themes is an API to switch the themes on certain conditions.
Usage
Write an another plugin file and use the Conditional Themes API as the example below:
add_action('plugins_loaded', 'my_conditional_themes_setup', 100);

function my_conditional_themes_setup()
{
// Switch to Twenty Eleven theme if the visitor use Internet Explorer.
Conditional_Themes_Manager::register('twentyeleven', function() {
global $is_IE;
return (bool) $is_IE;
});

// Switch to Twenty Thirteen theme if the user has administrator role.
Conditional_Themes_Manager::register('twentythirteen', function() {
return current_user_can('administrator');
});

// Switch to a custom theme if the visitor use a mobile device.
Conditional_Themes_Manager::register('mobile', 'wp_is_mobile');
}

Another example, With enabling persistent mode.
add_action('plugins_loaded', 'my_conditional_themes_setup', 100);

function my_conditional_themes_setup()
{
// Enable the switcher persistent mode.
Conditional_Themes_Manager::set_option('persistent', true);

// Switch to Twenty Sixteen theme when we being on 2016.
Conditional_Themes_Manager::register('twentysixteen', function() {
return (date('Y') == 2016);
});

// Switch to Twenty Fifteen theme when the site reaches 500 post.
Conditional_Themes_Manager::register('twentyfifteen', function() {
return ((int) wp_count_posts() > 500);
});
}

Note: You can use Code Snippets plugin to add the code snippets to your site.
Contributing
Developers can contribute to the source code on the Github Repository.

延伸相關外掛

文章
Filter
Mastodon