0

I have created numbers of websites. They are www.example.com, subsite1.example.com, subsite2.example.com and subsite3.example.com. I want to make a div that show different content. The example below is what i wanted.

Example: (this may not a correct code. But was trying to tell what i'm asking in this question).

    <?php if (is_site1()) { ?>
    <div class="div">
    Content for main site
    </div>
    <?php } ?>

    <?php if (is_site2()) { ?>
    <div class="div">
    content for sub site 1
    </div>
    <?php } ?>

    <?php if (is_site3()) { ?>
    <div class="div">
    content for sub site 2
    </div>
    <?php } ?>

    <?php if (is_site4()) { ?>
    <div class="div">
    content for sub site 3
    </div>
    <?php } ?>

This function is similar to code below:

<?php if (is_single() || is_achive()) { ?>
Show content
<? php } >

I want to place this function in my homepage. So that, the div takes effect everytime i switching the sites.

Please do let me know if you unsure of this question. I'm wondering if this could be done? Appreciate your help!

1

Do the sites have different wordpress installs? If so, they probably have different names and you could use

<div class="different-content">
if (get_bloginfo('name') == "site-1") {
    // show stuff for blog named "site-1"
} elseif (get_bloginfo('name') == "site-2") {
    // show stuff for blog named "site-2"
} else {
    //if it's not any of the sites above, show this
}
</div>

If they don't have different names you could do the same with

$host = $_SERVER['HTTP_HOST'];
$subdomain = array_shift((explode(".", $host)));

and checking for the subdomain instead of blog name.


New try.

In your functions.php add a function like this

function check_site($name) {
    if (get_bloginfo('name') == $name) { return true; }
    else { return false; }
}

now in your template (header.php/single.php etc..) you can use it like

<?php if (check_site('site_1')) { ?>
    <div class="div">
    Content for main site
    </div>
<?php } ?>
8
  • What do you mean by different wordpress installs? I install my wordpress in my cpanel and enabled the multisite during the wordpress installation. By then, i added sub sites in the wordpress admin area. Are you trying to ask this?
    – Jornes
    Mar 17 '15 at 11:43
  • Well yeah if you are using multisite all of the blogs should have their own settings and thus you should be able to check the site by name. edit: I have to say I haven't really worked with multi site installations so I don't know the exact "if" sentence. Check codex.wordpress.org/WPMU_Functions/get_blog_details
    – jimihenrik
    Mar 17 '15 at 11:54
  • I know the name of the site. But, i would like to ask, would you please show me a clearer instruction how to make it? I'm newbie in coding. And, i would like to make the code format as displayed in the question i asked. Just like if is_single() then the div shows A content , and if is_achive() then the div shows B content. Would be easier. Thanks! Jimihenrik.
    – Jornes
    Mar 17 '15 at 11:57
  • The problem with "is_site1()" is that you have to define that function. So you would have to define a function for every different blog name then. Do you have one theme that covers all the sites? So are you just editing one set of files?
    – jimihenrik
    Mar 17 '15 at 12:03
  • Yes! I have one theme covers all sites.
    – Jornes
    Mar 17 '15 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.