首页 文章

多主题wordpress插件的想法

提问于
浏览
3

我有一个想法,以盎司运行多个wordpress主题 . 如果可能的话,这可能是构建wordpress插件的好事 . 是的,如果不是非常艰难,我可能会承担这样的任务 .

(另外,如果你有兴趣和我合作,请告诉我(发表评论),我在javascript和php上都很不错,但不是很好,并且会喜欢一些帮助!)

这就是我看到它的工作原理:当前的“设置”主题可以在这里访问:“www.foo.com/”这里可以访问第二个主题:“www.foo.com/index.php?set_theme = theme2&”这里可以访问第三个主题: “www.foo.com/index.php?set_theme=THEME_NAME_HERE&”等...

这可以用于javascript后退 . 例如,如果您访问www.foo.com/?page_id=9并启用了javascript,则会将javascript重定向到“www.foo.com/index.php?set_theme=THEM_WITH_JAVASCRIPT&page_id=9” .

这就是我想象插件代码的外观/工作方式:

if(isset($_GET['set_theme'])){
       $loadme = cleaned($_GET['set_theme']);       
       if($loadme exists){
          loadtheme($loadme);
       } else {
          //go on as usual, as if this plugin doesnt exist
       }
    } else {
       //go on as usual, as if this plugin doesnt exist
    }

当然,所有的链接都必须广告?set_theme = FOOBAR&

所以,我的主要问题是:

  • Wordpress如何以及在何处选择当前主题?

  • 您如何/在何处修改内部链接 -
    if(isset($ _ GET ['set_theme'])){echo "?set_theme=" . $ _GET ['set_theme']; }

  • 你知道有什么好的网站能指出我如何制作WP插件的正确方向吗?

3 回答

  • 1

    找到一个98%的插件 . Wordpress主题切换器重装上阵 .

    刚刚更改了ts_get_theme()函数,如下所示:

    function ts_get_theme() {
                if (!empty($_GET["wptheme"])) {
                    return  $_GET["wptheme"];
                }        else {
                        return '';
                }
        }
    
  • 0

    您可能希望查看Theme Switcher插件以了解如何完成此任务 - 应该给您一些想法 .

  • 0

    不需要插件,只需将其添加到functions.php:

    function theme_switcher() {
        if(isset($_GET['theme']) $theme = $_GET['theme'];
        global $wpdb;
        if (isset($theme)) {
        $wpdb->prefix
        $queries = “UPDATE “.$wpdb->prefix.”options SET option_value = ‘”.$theme.”‘ WHERE option_name = ‘template’ OR option_name = ‘stylesheet’ OR option_name = ‘current_theme’;”;
        $wpdb->query($query);
        }
        }
    add_action('wp_head','switchTheme')
    

    然后使用 mywebsite.com/?theme=myNewTheme 切换它们

    免责声明:未经测试!!

相关问题