WordPress.org

Ready to get started?Download WordPress

Forums

TwentyTen: how to add random images? (2 posts)

  1. Guntis
    Member
    Posted 4 years ago #

    I need to customize TwentyTen theme by adding random images.
    In WP 2.X theme "falling_dreams" I used this function:

    <?php
    function header_graphic() {
    echo "/images/";
    $num=rand(0,24);
    echo "dream".$num.".jpg";
    };
    ?>

    Then in <head> section included:

    #header {
    background: url("<?php bloginfo('stylesheet_directory'); header_graphic(); ?>") no-repeat bottom center;
    }

    And in the <body> section this line:

    <div id="wrapper">
    <h1 id="header" onclick="location.href='<?php bloginfo('url'); ?>';" style="cursor: pointer;">

    And I had 25 header images appearing at random order.
    I wish I could do the same in TwentyTen theme, but as soon as I add header_graphic() function, I get an error message that this function is already defined in wp-includes/theme.php
    Can anyone post here what exactly where I need to change to show random images in the header?

  2. Digital Raindrops
    Member
    Posted 4 years ago #

    As a rule I prefix my functions so they do not conflict with any WordPress or PHP standard code calls, use a three digit prefix for your function and call like gun_.

    example:
    ?php
    function gun_header_graphic() {
    echo "/images/";
    $num=rand(0,24);
    echo "dream".$num.".jpg";
    };
    ?>

    and

    #header {
    background: url("<?php bloginfo('stylesheet_directory'); gun_header_graphic(); ?>") no-repeat bottom center;
    }

    David

Topic Closed

This topic has been closed to new replies.

About this Topic