Support » Fixing WordPress » How can I show a different image on each page?

  • Resolved carrieduncan


    Here’s a link for a Page based on the current Page template:

    Styles for image and right column are in the HTML (in the Page content itself). This bumps the Edit link to the left of the column (which you won’t be able to view) instead of right aligning (as set in the rule).

    I’d prefer to have all the CSS in the Page template rather than in the HTML, but can’t figure out how to give each page a different image if I do it that way. There will be about five pages. (SO new at this: 3 wks and counting.)

    Thanks very much in advance for any help you can provide.

Viewing 7 replies - 1 through 7 (of 7 total)
  • esmi


    Forum Moderator

    This might be a lot easier if you looked at setting up custom page templates. That way, you could have unique classes for each page type which you could then use in your stylesheet instead of having CSS in the page. You might also want to have a look at the is_page() conditional to control what image appears in what page.

    Nile Flores


    Yoast Support

    Well, here is one way I did this on one site, so maybe it might work for you.

    If you are not using a sidebar, you should consider it. So you will have a left column and right column. Left would be for your sidebar, and the right, of course… your content.

    Using the dynamic sidebars, you will be able insert the image into a widget and it will appear on the page.

    You will need to have several sidebars for your site if you want a different image for each page.

    I recommend if you have not already, try reading since you are new. Esmi has some recommendations for this. It is not difficult, and if you download a free template, you can look at the files to get an idea on what to do. 🙂 I use to find that it helps to do that.

    Many thanks to you both for your on-the-quick response — The is_page() conditional is exactly what I was looking for (thanks especially, esmi, for your links here and for your countless answers elsewhere) as I’d hoped to eliminate the custom page I’d already had to make. Posting an interim thank you because as I was trying to work with this, I broke my site but good. (Validated backup templates notwithstanding.) (Float: left in one of the divs renders the page blank in IE8. Oh, IE.)

    Since then, I’ve been at it for about 10 hours and counting attempting to get back to the perfect layout I had (in both FF and IE8), but will come back and post what did work once I’ve 1) fixed it the layout and 2) figured out how to place the image src code within the conditional php code.

    I tried Sidebar Generator, which worked fine with one sidebar defined and selected, but more than one kicked out 2 or 3 different images per page.

    Next up was is_page() conditional (which was my preference), but I’m still feeling around for syntax. Can anyone tell me why this isn’t working (this is what I have in my sidebar and I’m getting “unexpected $end” on the page)? Code as follows:

    <img src=”<?php
    if (is_page( ‘about’ )) {
    print ‘checkbook.jpg” />’;
    }elseif (is_page( ‘resources’ )) {
    print ‘resources.jpg” />’;
    }else {
    print ‘checkbook.jpg” />’;

    Thanks so much for any help you can offer.



    Forum Moderator

    a missing closing bracket:

    }else {
    print 'checkbook.jpg" />'; }

    AHHHH!!! Thank you! That worked!

    how would i enable an image to be printed from wordpress
    its a voucher at bottom of this page here:

    many thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How can I show a different image on each page?’ is closed to new replies.