[英]Wordpress image attachment
我正在使用此代码来获取所有工作正常的附件。 我的问题是我没有得到所需的附件大小。 当我不使用“ the_attachment_link($ attachment-> ID);”指定大小时 我得到缩略图,当尝试添加“中,小,大或完整”时,我仅得到完整尺寸。 我在这里想念什么吗? 我需要一些支持。
$args = array(
'post_type' => 'attachment',
'numberposts' => null,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
echo apply_filters('the_title', $attachment->post_title);
the_attachment_link($attachment->ID, 'medium', true);
}
}
嗨,尝试这样的事情:
query_posts( array('post_type' => 'attachment','numberposts' => null,'post_status' => null,'post_parent' => $post->ID));
<?php if (have_posts()) : while (have_posts()) :the_post();
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
?>
<img src="<?php echo $src[0]; ?>" width="174px" height="142px" alt="" />
<?php
endwhile;
else :
echo '<h3>Oops, something went wrong.</h3>';
endif;
wp_reset_query();
?>
} ?>
利用$ src [0]。 根据您的喜好设置高度和宽度。
希望这能解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.