2017-10-11 75 views
0

因此,我为我的网站制作了一些白色标签,它们位于服务器上的不同子域上。如何get_template_part()基于子域的url?

我想知道如果我能基于一个子得到一个模板的一部分,是这样的:

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

我一直在寻找onine有一段时间了,在这个没有太多的信息。

+0

我不明白,在不同的子域和不同的主题?是同一主题中每个子域的不同模板部件?并正在使用? –

回答

0

在这个例子中,我们有两个领域:

1)设置子域名指向到不同的目录上:

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

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

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