The MU forums have moved to WordPress.org

message if blog id (8 posts)

  1. matt1
    Member
    Posted 4 years ago #

    Hi everyone

    I am trying to use the same theme across several blogs but show a different message in the header depending on what blog the user is currently viewing.

    the code i am using is

    <?php $result = get_blog_details($blogId)->blog_id;
    if($result = 1){
    	echo "message1";
    }
    if($result = 2){
    	echo "message2";
    }
     if($result = 3){
    	echo "message3";
    }
    if($result = 4){
    	echo "message4";
    } ?>

    However, when I view any of these blogs, it shows all the messages instead of just a single one. Can someone help me with this please?

  2. matt1
    Member
    Posted 4 years ago #

    '<?php
    $blog_details = get_blog_details(1);
    echo 'Blog '.$blog_details->blog_id.' is called '.$blog_details->blogname.'.';
    ?> '

    I used this script and found each subblog returns the value of 1. Help please

  3. tmoorewp
    Member
    Posted 4 years ago #

    If you are trying to use a different message per blog, why not use the tagline under Settings -> General? It is designed to do just that.

    Also, in your if statements, you are missing an equal sign.

    Those should read if( $result == 1).

  4. matt1
    Member
    Posted 4 years ago #

    the tagline I am already using for something else, ill try what you have said

  5. harvknight
    Member
    Posted 4 years ago #

    also try to use 'elseif' instead of 'if' only.

  6. matt1
    Member
    Posted 4 years ago #

    Hi i still need help, no text shows up, I have tried what was said here 'elseif'. I can't use the tagline because I am already using it for something important.
    Also, each sub blog returns the value of 1.
    I am just trying to show a message depending on what blog the person is looking at so I can put
    Your current Location is: *%*

    Once again I can't use the blog description line.

    Any help is appreciated,

  7. matt1
    Member
    Posted 4 years ago #

    <?php $wname = get_blog_details( $blogId )->blog_id;
    if($wname == 1){ echo "Location 1";}
    elseif($wname == 2){ echo "Location 2";}
    elseif($wname == 3){ echo "Location 3";}
    elseif($wname == 4){ echo "Location 4";} ?>

    alternative please.

  8. andrea_r
    Moderator
    Posted 4 years ago #

    "I am just trying to show a message depending on what blog the person is looking at so I can put
    Your current Location is: *%*"

    In header.php where you want this to show, put:

    Your current Location is: <?php bloginfo('siteurl'); ?>

    That will give the URL of the current blog. All you need is the right template tag to pull the details of the current blog.
    http://codex.wordpress.org/Template_Tags/bloginfo

    No need to check and see what blog you're on by ID.

About this Topic