如何从wordpress中的特定帖子ID获取附件

时间:2013-05-29 16:13:49

标签: wordpress

$argsThumb = array(
    'order'          => 'ASC',
    'post_type'      => 'attachment',
    'post_parent'    => $post->ID,
    'post_mime_type' => 'image',
    'post_status'    => null
);
$attachments = get_posts($argsThumb);
if ($attachments) {
    foreach ($attachments as $attachment) { ?>

    <div class="item">
        <a href="<?php wp_get_attachment_url($attachment->ID, 'large', false, false); ?>" class="zoom" rel="group">
            <span class="thumb">
                <img class="small" src="<?php wp_get_attachment_url($attachment->ID, 'medium', false, false); ?>" />
            </span>
        </a> 

    </div>

<?php } } ?>

1 个答案:

答案 0 :(得分:1)

wp_get_attachment_url只需要一个参数+你需要回应:

<?php echo wp_get_attachment_url( $attachment->ID ); ?>

注意:要获取特定图片尺寸,请使用wp_get_attachment_image_src