• Resolved whatisstephenharperreading

    (@whatisstephenharperreading)


    Hi everyone,

    I was wondering if anyone out there knows of a widget or coding scheme that I could use to thumbnail images placed within individual posts with headings of those posts in my sidebar. Here’s the site I’m working on:

    https://www.whatisstephenharperreading.ca/wordpress/

    Currently, each posting has a cover of a book with the sidebar listing each post’s title. I’d like to be able to add the cover of the book to this list as well, preferably in two columns.

    Any help would be immensely appreciated.

    Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The first thing that pops into my head is to use custom fields for this. Create a custom field that you’ll fill in with the link to your book image. Then set up your sidebar so that if that custom field (let’s call it bookcover) exists, it’ll display. If there is no custom field defined, it won’t display. Something like this:

    <?php
    if(get_post_custom_values('bookcover')) :
    foreach(get_post_custom_values('bookcover') as $bookcover) {} ?>
    				[Title of your book] <img src="<?php $location ?>" />

    This might work, but I haven’t tested it. I can see it being a problem in that it would display the bookcover for the current post, not for the ones necessarily in the sidebar. I’m sure there’s a way to modify this and tell WordPress the ID of the entry to pull custom field information from. But does this idea make sense to you? That’s the more important step toward making it happen.

    I’m not sure what you mean by two columns. Are you just referring to your two lists of Current and Previous?

    Yep, this will do it for you. You just have to create a custom field for each post called “post_thumb”

    <?php $myposts = get_posts('numberposts=5&offset=0');
    foreach($myposts as $post) :?>
    <?php $thumbnail = get_post_meta($post->ID, 'post_thumb', true); ?>
    <ul>
    <li><a href="<?php the_permalink(); ?>"><?php the_title();?>
    <img src="<?php echo $thumbnail; ?>" alt="<?php the_title(); ?>" />
    </a></li>
    </ul>
    <?php endforeach; ?>

    You can see it working here: https://cssdivine.com/?page_id=482

    Just place that in your template files wherever you want the images to show up. Like if you want it in the sidebar, most likely it’s a file called “sidebar.php”

    Thread Starter whatisstephenharperreading

    (@whatisstephenharperreading)

    Many thanks jessn! I’m new to WordPress so I’m still learning, but even I could get your code to work (pretty much) on my first try!

    Thread Starter whatisstephenharperreading

    (@whatisstephenharperreading)

    One more thing: is there any chance I could get the thumbnails to display side by side in two columns? For example, books number 1 and 2 would be side by side at the bottom, with 30 and 31 next to each other at the top. I suppose this would mean that there would be a blank spot when displaying an odd number of books, but I could live with that.

    Thanks again!

    Sorry I replied so late. I think you could achieve that by styling your CSS to display your

    • items side by side, then only having it wide enough so only two could fit on a row and then the rest get bumped down.

    Would there be any way to specify the thumbnails size through this code? I know I could just change the thumbnail size, but I actually have this being generated in two places using the same custom field. It’d be nice to use the same image but hard code each individual page to display that thumb with specific dimensions.

    Any ideas? seems like css could do this, but alas… I am a noobie ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to add images from individual posts to the sidebar’ is closed to new replies.