Wordpress - return last image uploaded

Status
Not open for further replies.

radio

Unconsciously competent.
Nov 18, 2007
1,535
48
0
auction2post.com
This will return the last image uploaded which can then be used as a thumbnail on the homepage in a magazine style theme. I know there's a plugin that will return the FIRST image, but it would make more sense to return the last image since that can be updated/edited/etc. (unlike the first image uploaded). My question - is this a decent way to do it or would this call 20+ times be excessive (one call for each thumbnail).

Code:
<?php
global $wpdb;
$attachment_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post->ID' AND post_status = 'inherit' AND post_type='attachment' ORDER BY post_date DESC LIMIT 1");
?>
<?php echo get_attachment_icon($attachment_id); ?>
I'm doing this so that a user can avoid using custom fields for thumbs (no FTP). Wordpress gurus let me know if there's a cleaner way to do this. Thanks!
 


Status
Not open for further replies.