Tweaking the dp_attachment function
-
Help please!
On my blog, https://www.incredibledad.com, the theme I’m using has the following code to get thumbnail images for summary of posts in the middle of the home page.
# Displays post image attachment (sizes: thumbnail, medium, full) function dp_attachment_image($postid=0, $size='thumbnail', $attributes='') { if ($postid<1) $postid = get_the_ID(); if ($images = get_children(array( 'post_parent' => $postid, 'post_type' => 'attachment', 'numberposts' => 1, 'post_mime_type' => 'image',))) foreach($images as $image) { $attachment=wp_get_attachment_image_src($image->ID, $size); ?><img src="<?php echo $attachment[0]; ?>" <?php echo $attributes; ?> /><?php } }
Unfortunately, instead of picking up the first image in the post, it’s picking up the second image in the post (unless the first image is the only image).
2 questions please:
1) Is there a way I can force it to always pick up the first image?
2) Is there a way to perhaps use a custom field to force an image?Many thanks in advance!
ID
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Tweaking the dp_attachment function’ is closed to new replies.