• I want to use different background images for my content h2
    here is the site: http://enamoured.eightcrazydesigns.com/

    What I’d REALLY like to do is to have 4 different images that would be used. The first excerpt with image 1, second excerpt with image 2, third with image 3, fourth with image 4, fifth with image 1, etc.

    However I’ve also considered just using two images and designating them based on odd and even post numbers.

    Any clue how to do this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • you could try to add a counter variable into the loop, and output a css class to the h2 tag, using this counter; something like:

    <?php $bg_counter = 0;
    if( have(posts) ) : .....loop starts......)
    ?>
    
    <h2 class="<?php echo 'title-bg-' . ($bg_counter%4+1); $bg_counter++; ?>"><?php the_title(); ?></h2>
    
    <?php .....rest of the loop..... ?>

    the part $bg_counter%4 uses the modulus operator, i.e. it returns the remainder of a division (in this case division by 4)

    style with
    h2.title-bg-1 { }
    etc

    Thread Starter eightcrazy

    (@eightcrazy)

    thanks so much! I use a hooks plugin

    I have the following hooks:

    before_loop

    _loop

    after_loop

    can you give me direction as to how I would best apply your suggestion using the hooks

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Different content h2 background images’ is closed to new replies.