I have a single installation of Wordpress that is powering two domain names. To put it very simply, Site A has four static pages, and Site B has four static pages, but they both share a common blog-posts page.
Site A should have a navbar at the top that points to the other Site A pages and Site B should have a navbar that points to the other Site B pages.
Since they (necessarily) share a common WordPress theme, in the header.php
file I would like to put a PHP if
statement for a block of code that is the Site A nav and another for the Site B nav. But I'm not sure what condition to actually check for. Is t开发者_开发技巧here some way I can cause some pages to identify themselves to PHP as belonging to Site A, and others to Site B?
You could set variables in both sites before the header call, then use an if statement to show the right navigation.
Site A
<?
$site = 'A';
require('header.php');
?>
header.php
<?
if($site == 'A') {
//Site A nav
} else {
//Site B nav
}
?>
However, if your two sites have different domain names, you could look at the $_SERVER
global and key off of that directly in your header.php
instead.
If this two websites have different domain name you can validate by doing:
if($_SERVER['HTTP_HOST']=="sitea.com"){
//code for site a
} else {
//code for site b
}
if ($_SERVER['SERVER_NAME']=="www.whatever.com") {
//show site a header
}
精彩评论