user3550879
user3550879

Reputation: 3469

putting a div over a specific image using php

I have this code which detects the last image in the images in my Wordpress post

I want to alter it to put the div #up-arrow over-top the last image.

html

        <?php
        preg_match_all('/(<img [^>]*>)/', get_the_content(), $images);
        for( $i=0; isset($images[1]) && $i < count($images[1]); $i++ ) {
        if ($i == end(array_keys($images[1]))) {
        echo sprintf('<div id="last-img">%s</div>', $images[1][$i]);
        continue;
        }
            echo $images[1][$i];
        }
    ?> 

css

#up-arrow { position: absolute; z-index: 10; }

Upvotes: 0

Views: 159

Answers (1)

Ivnhal
Ivnhal

Reputation: 1095

Here is an example

You need to wrap html in

echo sprintf('<div id="last-img">%s</div>', $images[1][$i]);

as described in example.

Upvotes: 1

Related Questions