• Hi,

    I’m looking to add a different image into the sidebar for each Page (not post) – each image is specific to a page – not random.
    Any ideas?
    I’ve tried all sorts!
    thanks,
    Bitsy x

Viewing 7 replies - 1 through 7 (of 7 total)
  • You can use custom fields for this.

    You have to pay attention to where your loop is however. If your sidebar comes before or after the wp loop(which it usually does) then you can use this snippet to get the custom field value.

    Or you can search the plugins for a widget.

    Thread Starter bitsyandkitty

    (@bitsyandkitty)

    Thanks racer but I’m not so clear – so do i add this code to the sidebar.php

    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, ‘customField’, true);
    ?>

    ?
    change customField for something like ‘page-imag’e, create the custom filed in the page and add the image?

    i, surprisingly, drew a blank on widgets that do this simple – seemingly – function? There’s room for one out there you know!.

    thanks,
    Best, Bitsy x

    Yep. When making the page in the custom field section under “name” input the name of the field. (You will only need to do this once. Then it becomes part of the drop down choices.) In the “value” side input the full url to the image path previously uploaded somewhere on your site files(or uploads).

    I like to use a conditional statement then(in your case in the sidebar where you want the image to appear) so I can do something if no image was set. (Like show a default image, etc.)

    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    $image = get_post_meta($postid, 'page_image', true);
    if ( $image != '' ) { ?>
       <img src="<?php echo $image; ?>" />
    <?php } else { ?>
       <img src="put an alternate image here" />
    <?php } ?>
    Thread Starter bitsyandkitty

    (@bitsyandkitty)

    thanks racer – that’s working great. all very easy when you know how eh!

    many many thanks for the code.
    xx

    Glad it worked out!

    Thread Starter bitsyandkitty

    (@bitsyandkitty)

    Hi,

    i’m hoping Racer X is out there as you help was really fab previously.

    I am using a theme which has a home page pulling up the latest posts – i want this to pull up pages instead. How can i change the code to do that? It has four sections like so;

    [Code moderated as per the Forum Rules. Please use the pastebin]

    any ideas? or anybody else for that matter!

    faxon22

    (@faxon22)

    just wanted to say thank you for this tutorial. This is such a huge help. Many thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Add different image in sidebar on each PAGE’ is closed to new replies.