The MU forums have moved to WordPress.org

Help with PHP coding for each blog? (9 posts)

  1. theblade24
    Member
    Posted 17 years ago #

    I'm trying to do a php include that changes with each blog in MU based on blog id number.

    Same theme used for all blogs.

    This prospective php code would be hardcoded into the sidebar template.

    What I would like in simplified form is:

    If blog-id=1 display

    <?php
    @ini_set('expose_php', 'Off');
    @include "/var/www/html/domain/site_templates/site_1_1.php";
    ?>

    else if blog-id=2 display

    <?php
    @ini_set('expose_php', 'Off');
    @include "/var/www/html/domain/site_templates/site_1_2.php";
    ?>

    else if blog-id=3 display

    <?php
    @ini_set('expose_php', 'Off');
    @include "/var/www/html/domain/site_templates/site_1_3.php";
    ?>

    So the include changes by blog.

    Is it possible to do that? How would something like that be coded?

  2. andrewbillits
    Member
    Posted 17 years ago #

    What's up with the @ symbols?

  3. mysorehead
    Member
    Posted 17 years ago #

    @ means don't fail on error doesn't it? I've never used it.

    Why don't you just do:

    include "/var/www/html/domain/site_templates/site_1_".$blog_id.".php";

    Richard

  4. theblade24
    Member
    Posted 17 years ago #

    mysorehead you are the bomb!!

    That works perfectly!!!!

    Thank you so much!

  5. theblade24
    Member
    Posted 17 years ago #

    mysorehead.... problem.... this approach you gave me above works great in the sidebar or anywhere else... but I need to move this code to the footer.

    When I move the code to the footer the ".$blog_id." is not working and it is not pulling the blog id.

    Is there something or a reason why ".$blog_id." won't work in the footer? Is there a way make it work there?

  6. andrewbillits
    Member
    Posted 17 years ago #

    Give this a whirl:
    $wpdb->blogid

    Although technically, $blog_id should be available pretty much anywhere.

    Thanks,
    Andrew

  7. lunabyte
    Member
    Posted 17 years ago #

    It should be, but sometimes needs to be called as a global first. Same with wpdb, current_user, etc.

  8. andrewbillits
    Member
    Posted 17 years ago #

    That's a good point. If you're trying to use it inside of a function place the following at the top of the function:

    global $blog_id;

  9. mysorehead
    Member
    Posted 17 years ago #

    yeah, what they said....

About this Topic

  • Started 17 years ago by theblade24
  • Latest reply from mysorehead