【问题标题】:Multi theme wordpress plugin idea多主题wordpress插件理念
【发布时间】:2011-02-03 23:46:05
【问题描述】:

我有一个以 ounce 运行多个 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&

所以,我的主要问题是:

  1. Wordpress 如何以及在何处选择当前主题?
  2. 您将如何/在哪里做广告以修改内部链接-
    if(isset($_GET['set_theme'])){ 回声“?set_theme =”。 $_GET['set_theme']; }
  3. 你知道有什么好的网站可以为我指明如何制作 WP 插件的正确方向吗?

【问题讨论】:

    标签: php plugins wordpress


    【解决方案1】:

    您可能想查看Theme Switcher 插件,看看它是如何完成这项任务的 - 应该会给您一些想法。

    【讨论】:

      【解决方案2】:

      其实不需要插件,只要把这个添加到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 切换它们

      免责声明:未经测试!!

      【讨论】:

      • 你有几个错误,你还需要在将它发送到数据库之前清理 $theme
      【解决方案3】:

      找到了一个 98% 的插件。 Wordpress 主题切换器已重新加载。

      只是把ts_get_theme()函数改成如下:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-06-29
        • 2014-10-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-12
        • 1970-01-01
        相关资源
        最近更新 更多