WordPress 图片附件
我正在使用此代码来获取所有帖子附件,效果很好。 我的问题是我没有获得所需的附件大小。当我没有使用“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);
}
}
I am using this code to get all posts attachment which it is doing fine.
My problem is I am not getting the desired attachment size. When I don't specify the size with "the_attachment_link($attachment->ID);" I get the thumbnail and when I try by adding "medium, small, large, or full" I get the full size only.
Am I missing something here? I need some support please.
$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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您好,尝试这样的操作:
使用 $src[0]。
根据您的喜好设置高度和宽度。
希望这能解决它。
Hi try something like this:
make use of the $src[0].
set the height and width according to your preference.
hope this solves it.