The MU forums have moved to WordPress.org

Check which blog the user is on? (6 posts)

  1. hempsworth
    Member
    Posted 17 years ago #

    Hi,

    Is there a string of code that will enable me to check which blog the user is on, and then use that data. Along the lines of this:

    <?php if($_SERVER['HTTP_HOST'] == 'www.domain.com/news/' || $_SERVER['HTTP_HOST'] == 'domain.com/news/') {
    include ('http://source.domain.com/php/navigation_news.php');
    } else {
    include ('http://source.domain.com/php/navigation_home.php');
    }
    ?>

    But obviously that doesn't work :P

    What I'm trying to accomplish is:
    If current blog is "news" include the file 'navigation_news.php', otherwise include the file 'navigation_home.php'.

    I don't have any PHP knowledge so I'm guessing at the code!

  2. ceejayoz
    Member
    Posted 17 years ago #

    If /news/ is a separate blog from /,

    get_bloginfo('url')
    should do the trick.

    If /news/ is just a page within the main blog, though, you'll want to use $_SERVER['REQUEST_URI'] or something similar.

  3. hempsworth
    Member
    Posted 17 years ago #

    How would I write out the function using

    $_SERVER['REQUEST_URI']

    because some of the sections are blogs, and some aren't.
    I tried

    <?php if($_SERVER['REQUEST_URI'] == 'www.domain.com/news/' || $_SERVER['REQUEST_URI'] == 'domain.com/news/') {
    include ('http://source.domain.com/php/navigation_news.php');
    } else {
    include ('http://source.domain.com/php/navigation_home.php');
    }
    ?>

    but that didn't work, it just includes navigation_home.php even though I'm on http://domain.com/news/

  4. hempsworth
    Member
    Posted 17 years ago #

    I also tried it using the

    get_bloginfo('url')
    method you suggested, is this the right way to impliment it?

    <?php
    $blog_url = get_bloginfo('url');
    if($blog_url == 'http://domain.com/news/') {
    include ('http://source.domain.com/php/navigation_news.php');
    } else {
    include ('http://source.domain.com/php/navigation_home.php');
    }
    ?>

    because that doesn't work either!

  5. ceejayoz
    Member
    Posted 17 years ago #

    Try doing echo get_bloginfo('url'); to see what's output. It may be something simple - perhaps it's outputting the URL without the ending slash or something.

    For troubleshooting, when in doubt, echo the variable you're working with - it'll solve a lot of problems.

    Same thing with $_SERVER['REQUEST_URI'] - it's not going to output something like "www.domain.com/news/", it'll output everything after the domain name (including any query strings) - so "/news/", in your case. When in doubt, echo.

  6. hempsworth
    Member
    Posted 17 years ago #

    Thank you, the navigation is working perfectly now!
    I change things around a bit, they no longer

    include

    seperate navigation pages, instead they change the class of a

    <li>

    to

    <li class="active">

    when they are on that blog.
    Thanks for the advice :)

About this Topic

  • Started 17 years ago by hempsworth
  • Latest reply from hempsworth