>>harcode in sidebar.php, does not display anything
insert html in text widget, displays a white box<<
Are you linking to the file correctly? If you’re using relative path, that won’t work. Is the image uploaded to the server?
Hope – I’ve done something similar before, but not this exact thing. I mean, you *can* hard code it in the sidebar (within the sidebar.php file, or by using a text widget and plugging it in there). But if you want it more automated, you can use a query and custom fields.
Basically, in your functions.php file put in this:
function postimage() {
// get the post meta info
$key = "postimage";
$id = get_the_ID();
$custom = get_post_meta($id, $key, true);
echo $custom;
}
Then in your sidebar.php file (or within a widget that you can enter in PHP code), put in:
<?php
$image = new WP_query ('showposts=1');
if(have_posts()) : while($image->have_posts()) : $image->the_post; ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php postimage(); ?></a>
<?php endwhile; endif; rewind_posts; ?>
where you want the image to appear.
Then when you write a post, scroll down to the bottom and find the “Custom Fields” area. Expand it, and for “Key” type in “postimage” (you’ll only have to do it the first time – afterwards it’ll be available in your dropdown for the key). For “value” put in the HTML code for your image. If you want to make it pretty simple, within the post content area, add an image like you normally would and have it insert the code for you. Highlight, copy and paste it into the “Value” area. (Delete it from the post if you don’t want it to show up in there) “Add Custom Field” and then save your post.
Your sidebar should then show the most recent post’s image, linked to the post.
I haven’t tested that – but like I said, I’ve done similar stuff, so that code (even though I just wrote it off the top of my head) will probably work.
Hope that helps.