Wordpress Themes - WP Forum at BFA
Click Here To DONATE! Support the theme development, get more attention and additional benefits based on your donation level. Your forum name will be highlighted.

Wordpress Themes - WP Forum at BFA » WordPress Themes » Atahualpa 3 Wordpress theme » Sidebars & Widgets »

Random featured images in a widget


Build custom WP THEMES, without
coding.
Click here for THEMEFRAME

From the author of Atahualpa, the #1 most
downloaded (700,000+) theme @ wordpress.org
  #1  
Old Sep 10, 2011, 09:25 AM
peri
 
9 posts · Aug 2011
Random featured images in a widget

Hi,

Each post I make has a nice little handcrafted featured image to go with it.

I want to to put (say) 10 stacked random images in the sidebar (no text, just the thumb with some canvas around it), resized to 150x75 and clickable to take someone to the post it represents.

In the last week I must've tried every widget that has anything at all to do with featured images and the sidebar, but I still cant find anything.

I found one (special recent posts) which does EXACTLY what I want, but it only takes its images from the last X recent posts. I contacted the author and asked if he could tell me how to make it choose from all blog posts, not just the last few. He said it stretched the plugin too far and he had no plans to implement anything like that

The closest thing I've found myself is to use the php widget (mentioned elsewhere in this forum) and use the following

Code:
<?php
$thumbnails = get_posts('numberposts=10&orderby=rand');
foreach ($thumbnails as $thumbnail) {
if ( has_post_thumbnail($thumbnail->ID)) {
echo '<a href="' . get_permalink( $thumbnail->ID ) . '" title="' . esc_attr( $thumbnail->post_title ) . '">';
echo get_the_post_thumbnail($thumbnail->ID, 'thumbnail');
echo '</a>';
}
}
?>
But this is basically a straight copy of someone elses code posted in the WP codex (ie I dont really understand it) and It doesn't resize the images.

Can someone either suggest a plugin I could try that does what I want, or failing that give me some ideas of how to go about getting this code to work as I want?



Thanks



EDIT

I've managed to work out that putting this as a css insert will place it where I want it, and resize the image, but it doesn't do a 'proper' job - images seemed squashed or stretched to fit. There must be a better way

Code:
img.wp-post-image {
    background: none repeat scroll 0 0 transparent;
    border: 1px solid;
    margin: 0 0px 5px 16px;
    width: 150px;
    height: 75px;
    padding: 0;
}



Edit 2

Ok, I've realised that you cant really use CSS to resize an image.

The widgets that do resize use routines and methods that are beyond me.

I've manually resized the thumbs to the size I need, and using the bit of php and css from above I've got a passable result

Hope that helps someone else

Last edited by peri; Sep 13, 2011 at 10:06 AM.

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use random image code to display random flash banner? blueprairie Header configuration & styling 0 Mar 18, 2010 01:30 PM
How to get the header images to rotate in a random fashion? ptuquoc Header configuration & styling 3 Jul 29, 2009 05:02 AM
Calling random images in the sidebar, similar to header cowgirlgeek Sidebars & Widgets 1 Jun 30, 2009 06:41 PM
HELP PLEASE! Trying to use Stray Random Quotes Widget - Won't Work.... laurastone Sidebars & Widgets 1 Mar 30, 2009 05:33 PM


All times are GMT -6. The time now is 03:21 PM.


Powered by vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.