如何基于子域url get_template_part()?

时间:2017-10-11 14:12:15

标签: php wordpress wordpress-theming subdomain

因此,我为自己的网站制作了一些白色标签,它们位于服务器上的不同子域中。

我想知道我是否可以根据子域获取模板部件,如下所示:

if (subdomain = 'something') {
   get_template_part('template-part', 'header_test');
}

我现在已经搜索了一段时间,关于此的信息不多。

1 个答案:

答案 0 :(得分:0)

对于此示例,我们有两个域:

http://www.example.com
http://subdomain.example.com

要为子域使用不同的模板,我们可以通过以下步骤完成此操作:

1)设置子域以指向服务器上的其他目录:

Domain: /home/wherever/public_html
Sub-domain: /home/wherever/public_html_subdomain

2)将index.php文件复制到新的子域目录,并更新CRAFT_TEMPLATES_PATH变量以指向要包含模板的位置。在此示例中,两个模板文件夹都位于Web根目录之上。

// index.php for domain
define('CRAFT_TEMPLATES_PATH', realpath(dirname(__FILE__) . "/../templates").'/');

// index.php for subdomain
define('CRAFT_TEMPLATES_PATH', realpath(dirname(__FILE__) . "/../templates_subdomain").'/');

您的模板文件夹现在如下所示:

/home/wherever/public_html
/home/wherever/public_html_subdomain
/home/wherever/templates
/home/wherever/templates_subdomain
相关问题