for example i only want to show attached images which are 960px by 200px.
for example i only want to show attached images which are 960px by 200px.
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $main_post_id
);
$attachments = get_posts($args);
foreach ($attachments as $attachment)
{
the_attachment_link($attachment->ID, false);
}
That gets the image. Then check the size with an if statement asking:
filesize( get_attached_file( $attachment->ID ) );
can you place an if statement within a foreach loop? or where do you mean shall i put the if statement?
$filesize = filesize( get_attached_file( $attachment->ID ) );
if( $filesize == WHATYOUWANTTHEFILESIZETOBE){
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $main_post_id
);
$attachments = get_posts($args);
foreach ($attachments as $attachment)
{
the_attachment_link($attachment->ID, false);
}
else { echo 'No images for you!'; }
Not tested, but it gives you the idea.
thanks for your help!
i have a solution too, finally!
<?php
$attachments = get_children(
array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'post_mime_type' => 'image'
) );
foreach ( $attachments as $attachment_id => $attachment ) {
$src = wp_get_attachment_image_src( $attachment_id, 'full' );
if ($src[2] == 500){
echo wp_get_attachment_image($attachment->ID, 'full');
}
}
?>This topic has been closed to new replies.