我有一个网络站点安装有4个不同的子站点使用子目录样式:domain.com/ger, domain.com/fra, domain.com/esp等。
以上所有网站都使用相同的主题/模板。
在我的一个文件中,我想根据正在查看的站点添加几行自定义内容。
所以我认为一定有一种方法可以在用户查看页面时获得子网站的ID,然后显示特定于该子网站的内容。
像这样,也许:
<?php
If blog_id=2
{
?>
Content specfic to Germany
<?php
}
elseif blog_id=3
{
?>
Content specific to France
<?php
}
?>
但是我不知道如何在页面加载时获得子网站的id。
任何想法都将非常感激。
使用get_current_blog_id()
- http://codex.wordpress.org/Function_Reference/get_current_blog_id
$blog_id = get_current_blog_id();
switch ( $blog_id ) {
case 2:
// content here...
break;
case 3:
// alternative content...
break;
default:
// content when above IDs aren't matched...
}