【问题标题】:Find out if Wordpress multisite uses subdirectory or subdomain for new blogs了解 Wordpress 多站点是否为新博客使用子目录或子域
【发布时间】:2014-07-16 00:46:19
【问题描述】:

在创建新博客时,是否有检查 Wordpress 多站点安装是否使用子目录或子域选项的功能?

我正在使用函数wpmu_create_blog 创建新博客。 法典解释:

在子目录安装中,$domain 与主站点的域相同,路径是子目录名称(例如“example.com”和“/blog1/”)。在子域安装中,$domain 是新的子域 + 根域(例如 'blog1.example.com'),$path 是 '/'。

所以我需要一种方法来确定多站点是子目录还是子域安装。

【问题讨论】:

    标签: wordpress subdomain subdirectory


    【解决方案1】:

    好吧,我们有非常constant defined in wp-config.php

    if ( defined( 'SUBDOMAIN_INSTALL' ) ) 
    {
        if( SUBDOMAIN_INSTALL )
            echo '<h2>Is: SUBDOMAIN</h2>';
        else
            echo '<h2>Is: SUBDIRECTORY</h2>';
    }
    

    【讨论】:

      【解决方案2】:

      您可以使用wp_get_sites() 获取有关您的博客的信息。它将返回一个包含所有现有博客信息的数组。

      来自the documentation的示例结果:

      Array(
          [0] => Array(
              [blog_id] => 1
              [site_id] => 1
              [domain] => example.com
              [path] => /
              [registered] => 2013-11-08 17:56:46
              [last_updated] => 2013-11-08 18:57:19
              [public] => 1
              [archived] => 0
              [mature] => 0
              [spam] => 0
              [deleted] => 0
              [lang_id] => 0
          )
      
          [1] => Array(
              [blog_id] => 2
              [site_id] => 1
              [domain] => example.com
              [path] => /examplesubsite/
              [registered] => 2013-11-08 18:07:22
              [last_updated] => 2013-11-08 18:13:40
              [public] => 1
              [archived] => 0
              [mature] => 0
              [spam] => 0
              [deleted] => 0
              [lang_id] => 0
          )
      )
      

      [0] 将是您的主要博客,所以我会忽略这一点。但是通过查看之后的第一个博客,您应该能够获得信息。

      $info = wp_get_sites();
      if ($info[1]['path'] == "/") {
          // the installation uses subdomains
      }
      else {
          // the installation uses subdirectorys
      }
      

      当然,这仅在至少创建了一个额外的博客时才有效,但我找不到任何其他选项来检查。

      【讨论】:

      • 谢谢。那已经很有用了(不能投票,因为没有足够的声誉)。虽然我仍然想知道在尚未创建子网站时是否会有更好的解决方案。
      猜你喜欢
      • 2013-12-05
      • 1970-01-01
      • 2018-03-08
      • 2017-05-19
      • 1970-01-01
      • 1970-01-01
      • 2016-06-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多