• This might be a tricky one – or super easy. I’m fairly new to PHP and CSS.

    I’m using WordPress for CMS primarily and I’d like to have a specific image show up on each Page outside of the general loop.

    I’ve been able to get a static image to display on all the Pages via page.php and I’ve been able to get random images to display (via cut & paste of coding).

    But I’d like the images to be more specific.

    I.e. When you click on about us (page-id=4) I’d like image 4 to display.

    Any help would be appreciated.

    The site is still under development at: https://www.encounterthis.com/new2008

Viewing 3 replies - 1 through 3 (of 3 total)
  • I can see this being fairly easy, you just need to make a container for the image and name and style it in CSS, and that use some simple PHP to name the box in your XHTML.

    For instance (very simply)

    CSS:

    #box {
    width:300px;
    height:300px;
    padding:5px;
    }
    
    #box .dynpic1 {
    background:#000 url ('images/dynpic1.jpg')
    }

    Create a .dynpic 2, 3 and 4 etc. in the CSS.

    and for the PHP/XHTML:

    <div id="box">
    <div <?php if (is_page('[PAGE]')){ echo "class=\"dynpic1\">"; } ?>
    </div>
    </div>

    I’ve not tested this but that’s the basic idea.

    Thread Starter jblundell

    (@jblundell)

    not a bad idea – i’m wondering if IE would botch it up though ?? would there be a way to make it a regular image and not a background.

    either way I’ll have to give it a go and see what I can get when I get home.

    i’ll let you know. thanks

    Thread Starter jblundell

    (@jblundell)

    tried getting this to work. no luck so far. the suggestion makes sense but something must be missing.
    it builds the block like i want but won’t show the background color or the image.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘display image based on page-id’ is closed to new replies.