The MU forums have moved to WordPress.org

determing blog.dr in a css file (11 posts)

  1. billjones
    Member
    Posted 16 years ago #

    I want to use the same theme for all blogs, but each blog will have several header images that are rotated each time a page is loaded.

    Currently I have multiple copies of the same theme for each blog calling the following code. Under each theme is a folder called headers and rotator.php which does the rotating (the site is rhmpano.org)

    in the css file I use this code to do the image rotation.

    '#header02 {
    position:relative;
    background: url(headers/rotator.php) no-repeat center top;
    height:140px;
    }'

    In the header.php I then call it simply with
    '<div id="header02">'

    my ideal solution would be to have under blog.dr - blog-id a folder called headers with the header images and rotator.php which does the rotation and have the css file determine the url by the blogs id.

    This will probably also have to work with the multi-site plugin.

  2. dsader
    Member
    Posted 16 years ago #

    I'd use the Userthemes plugin. It will create a copy of each theme in the bogs.dir so you can make changes reflected on that blog alone.

    Have you tried the custom header API tutorial? Worked on themes in WPMU blogs.dir this way.

  3. billjones
    Member
    Posted 16 years ago #

    Forget that they are headers. I need to use the same theme for various reasons, Any changes would always be site wide with the exception possibly being the home theme.

    I would prefer it to be a css function call if possible.

    The php code that I am calling reads every jpg that is in the same folder as the code and randomly displays one of the pictures.

    Each blog will have a different set of pictures..

    So I need to know how to define a path that is unique to each blog id 1,2,3,4 etc

    My current css code that does what I want calls rotator.php located in a folder in the themes folder called headers.

    '#header02 {
    position:relative;
    background: url(headers/rotator.php) no-repeat center top;
    height:140px;
    }'

    I do declare that it will be 140 pixels high so that space is always reserved and show as black if the folder isn't found.

    Then I need to know how to declare that path in the css file.

    So, How do I define and declare a variable that is blog dependent and then how do I change the css code to be something like

    '#header02 {
    position:relative;
    background: url(&blogid_defined_path/headers/rotator.php) no-repeat center top;
    height:140px;
    }'

  4. andrea_r
    Moderator
    Posted 16 years ago #

    "The php code that I am calling reads every jpg that is in the same folder as the code and randomly displays one of the pictures.

    Each blog will have a different set of pictures..

    So I need to know how to define a path that is unique to each blog id 1,2,3,4 etc"

    Then I'd stick the folder of random images in each blog's specfic uploads directory. Way easier to find that way.

  5. billjones
    Member
    Posted 16 years ago #

    That's what I thought I said??? But half the time my wife says she doesn't understand anything I say.

    How would I write

    '#header02 {
    position:relative;
    background: url(bloguploadpath/headers/rotator.php) no-repeat center top;
    height:140px;
    }'

    I don't care if I use a different name then headers for the holding the images

  6. kgraeme
    Member
    Posted 16 years ago #

    Turn the problem around 180. Don't try to write a variable to the CSS file. Have the rotator.php write a line of CSS to your theme's header.php file using the wp_head function.

    So in your style.css you will have some static default background image for the header.

    In your rotator.php function, you will select a random image and have a function that generates a CSS declaration with that random image. Something roughly like:

    function getRandomImage () {
       whatever you do to select an image, get it's path, and return it when this function is called.
    }
    
    function showHeaderImage () {
    <style>
    #header02 {background: url(<?php getRandomImage(); ?>;)
    </style>
    }
    
    add_action('wp_head', 'showHeaderImage');

    In your header.php you will have (very abbreviated):

    <head>
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
    <?php wp_head(); ?>
    </head>

    So the CSS output by the add_action('wp_head') shows up after your default css and overrides just the image.

  7. andrea_r
    Moderator
    Posted 16 years ago #

    Actually, I initially read it as different folders within the theme directory itself - whcih is the same one for everyone. :) Tomayto, tomahto. :D

    kgraeme's got it. Well, one way to skin the cat. :D

  8. billjones
    Member
    Posted 16 years ago #

    I will admit I don't follow the above example, but I don't see how that would give me a different set of images to work with for each blog, they are different sets of images that will be random.

    Blog1 gets set 1 of 7 images to be displayed randomly

    Blog2 gets set 2 of 3 images to be displayed randomly

    Blog3 gets set 3 of 5 images to be displayed randomly

    Blog4 gets set 4 of 4 images to be displayed randomly

    Blog5 gets set 5 of 2 images to be displayed randomly

    My way that I can't get to work is to just insert a number into the css call that corresponds to the blog number

    '#header02 {
    position:relative;
    background: url(wp-content/blogs.dr/3/headers/rotator.php) no-repeat center top;
    height:140px;
    }'

    where the "3" is just the numeric number of the blog

    I have tried the defined paths that are in wp_settings and they don't work because I probably don't know the correct syntax.

    If it is possible!!! what would the syntax be is I used blog.dr via the uploadpath that has already been defines

    in wp-settings is

    'if( !defined( "BLOGUPLOADDIR" ) )
    define( "BLOGUPLOADDIR", WP_CONTENT_DIR . "/blogs.dir/{$wpdb->blogid}/files/" );'

    and then under / wp-content/blog.dr/3/files/headers (are my files and rotator.php script)

    I need to pass the 3

    If I'm clear, what would the syntax be for the following css statement

    '#header02 {
    position:relative;
    background: url(wp-content/blogs.dr/3/headers/rotator.php) no-repeat center top;
    height:140px;
    }'

  9. dsader
    Member
    Posted 16 years ago #

    Are you using http://ma.tt/scripts/randomimage/ ?

    $folder = '';

    becomes

    $folder = BLOGUPLOADDIR . 'headers';

    Or http://wphackr.com/random-header-image/ ?

    then
    $dir = get_template_directory() . '/images/header_images/';

    becomes
    $dir = BLOGUPLOADDIR . 'images/header_images/';

    At any rate, you are hitting your head against a wall if you are trying to execute php variable/constant within a .css - - can't be done. The css for your background must be passed to the header via php, not the other way around.

    kgraeme +1

  10. billjones
    Member
    Posted 16 years ago #

    Now you make me feel stupid because the answer was so simple and there all the time. I do have the problem of not knowing what a variable is sending if things don't work out right. How would I have the system return a simple text line telling me what the variable returned.

    In other words I want to see on the screen the value returned by
    blog_id and BLOGUPLOADDIR

    Thanks

  11. dsader
    Member
    Posted 16 years ago #

    <?php print_r($dir); ?>
    http://ca.php.net/print_r

About this Topic

  • Started 16 years ago by billjones
  • Latest reply from dsader