Skip to main content
Tweeted twitter.com/#!/StackWordPress/status/634903362828435456
edited body
Source Link
Krzysiek Dróżdż
  • 25.5k
  • 9
  • 53
  • 74

I'm using the following template code to display attachment links:

$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);
}

but after the link I need to display the file's size. How can I do this?

I'm guessing I could determine the file's path (via wp_upload_dir() and a substr() of wp_get_attachment_url()) and call filesize() but that seems messy, and I'm just wondering if there's a method built into wordpressWordPress.

I'm using the following template code to display attachment links:

$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);
}

but after the link I need to display the file's size. How can I do this?

I'm guessing I could determine the file's path (via wp_upload_dir() and a substr() of wp_get_attachment_url()) and call filesize() but that seems messy, and I'm just wondering if there's a method built into wordpress.

I'm using the following template code to display attachment links:

$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);
}

but after the link I need to display the file's size. How can I do this?

I'm guessing I could determine the file's path (via wp_upload_dir() and a substr() of wp_get_attachment_url()) and call filesize() but that seems messy, and I'm just wondering if there's a method built into WordPress.

added 92 characters in body
Source Link
Bobby Jack
  • 1.3k
  • 5
  • 15
  • 23

I'm using the following template code to display attachment links:

$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);
}

but after the link I need to display the file's size. How can I do this?

I'm guessing I could determine the file's path (via wp_upload_dir() and a substr() of wp_get_attachment_url()) and call filesize() but that seems messy, and I'm just wondering if there's a method built into wordpress.

I'm using the following template code to display attachment links:

$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);
}

but after the link I need to display the file's size. How can I do this?

I'm guessing I could determine the file's path and call filesize() but I'm just wondering if there's a method built into wordpress.

I'm using the following template code to display attachment links:

$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);
}

but after the link I need to display the file's size. How can I do this?

I'm guessing I could determine the file's path (via wp_upload_dir() and a substr() of wp_get_attachment_url()) and call filesize() but that seems messy, and I'm just wondering if there's a method built into wordpress.

Source Link
Bobby Jack
  • 1.3k
  • 5
  • 15
  • 23

How do I get the size of an attachment file?

I'm using the following template code to display attachment links:

$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);
}

but after the link I need to display the file's size. How can I do this?

I'm guessing I could determine the file's path and call filesize() but I'm just wondering if there's a method built into wordpress.