show how many attachments a wordpress post has
Wordpress Tips And Tricks
Files: <?php echo $wpdb->get_var( “SELECT COUNT(*) FROM $wpdb->posts WHERE post_parent = ‘$post->ID’ AND post_type = ‘attachment’” ); ?> |
Files: <?php echo $wpdb->get_var( “SELECT COUNT(*) FROM $wpdb->posts WHERE post_parent = ‘$post->ID’ AND post_type = ‘attachment’” ); ?> |
“This January, we’re putting the focus squarely on the characters and iconic heroes of the DCU,” said DCU Co-Publisher Dan DiDio. “Not only will we tell new stories some of the more-deserving with special one-shots, but we’ll be giving every title in the line a unique treatment that puts the spotlight on the heroes and villains that populate the DC Universe.”
You can see the placeholder covers below, when the actual covers come out I’ll put them here.
via DC Blog
I’ve re-added a blog to www.comiccovers.com Not much to say other then after a much needed rest from the comic book cover scan world I’m diving back in. Feel free to subscribe to either the Latest Blog RSS feed or the Latest Scan RSS feed.
This is how you can show the comment user’s level:
$user = get_userdata($comment->user_id); echo $user->user_level;
over on www.myconfinedspace.com I was having trouble keeping track of which posts had been properly tagged or not. using this code, you’ll be able to display the untagged posts. And edit button will appear when appropriate.
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('showposts=500'.'&paged='.$paged);
?>
if (!$tag) { ?>
<a href=""> - -
}
endwhile;
endif; ?>
please note the large number of posts that will be shown. Since it’s only the post titles that are loading there shouldn’t be a problem with 500 of them at once, but your server may not be the uber powerhouse that mine is
Another quirk of this bit of code is that each page is 500 posts of your material, and it only shows the ones that are untagged. so if you have untagged posts that are 4,000 posts back, you’ll need to click over to page 8 or 9 to see those posts pop up on this.
Want to show what posts are coming up? add this bit of code in:
$my_query = new WP_Query('post_status=future&showposts=1000&order=asc');
?>
I’ve had it happen a few times that my custom queries and even some of the ‘ishome’ or ‘isfrontpage’ queries weren’t working correctly. before you pull your hair out, try adding this immediately before your query:
not exactly sure why I was looking to do this, but here it is anyways:
note that you’ll need to have added the ‘list_first_image’ bit to your functions.php file.
add this to your theme’s “functions.php” page:
function list_first_image() {
$files = get_children('post_parent='.get_the_ID().'&post_type=attachment&post_mime_type=image');
if($files) :
$keys = array_reverse(array_keys($files));
$j=0;
$num = $keys[$j];
$image=wp_get_attachment_image($num, 'large', false);
$imagepieces = explode('"', $image);
$imagepath = $imagepieces[1];
$thumb=wp_get_attachment_thumb_url($num);
print " '$thumb' ";
endif;
}
alternatively you can also pass along some size requirements. this is the one that’s in use under each ‘single post’ on www.myconfinedspace.com :
function get_first_image() {
$files = get_children('post_parent='.get_the_ID().'&post_type=attachment&post_mime_type=image');
if($files) :
$keys = array_reverse(array_keys($files));
$j=0;
$num = $keys[$j];
$image=wp_get_attachment_image($num, 'large', false);
$imagepieces = explode('"', $image);
$imagepath = $imagepieces[1];
$thumb=wp_get_attachment_thumb_url($num);
print "";
endif;
}
once you have either of those added to your functions.php file, you can call them using :
or
$rand_posts = get_posts('numberposts=5&orderby=rand');
foreach( $rand_posts as $post ) :
?>