WordPress:获取附件,但不获取拇指后的附件
我的 functions.php 中有以下代码:
function get_images($size = 'thumbnail') {
global $post;
return get_children( array('post_parent' => get_the_ID(), 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
}
在我的 single.php 中,
<?php $photos = get_images('full'); ?>
<?php $x = 0; ?>
<?php foreach($photos as $photo): ?>
<?php if($x < 1): ?>
<img src="<?=wp_get_attachment_url($photo->ID)?>" alt="fullImg" />
<?php endif; ?>
<?php $x++;
?>
<?php endforeach; ?>
我只想在那里显示一张图像,但它也向我显示 post -拇指图像,我不想要,是否有选项可以排除它?
I have the following code in my functions.php:
function get_images($size = 'thumbnail') {
global $post;
return get_children( array('post_parent' => get_the_ID(), 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
}
And in my single.php
<?php $photos = get_images('full'); ?>
<?php $x = 0; ?>
<?php foreach($photos as $photo): ?>
<?php if($x < 1): ?>
<img src="<?=wp_get_attachment_url($photo->ID)?>" alt="fullImg" />
<?php endif; ?>
<?php $x++;
?>
<?php endforeach; ?>
I want to show just ONE image there, but it shows me also the post-thumb image, which I don't want, is there an option to exclude that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那是一些疯狂的编码!在函数中接受大小是没有意义的,因为它只是返回一个 post 对象数组。
获得帖子后,然后使用适当的附件功能来获取有关您想要的附件大小的信息。
我会建议使用这样的函数;
并将其付诸实践;
更新:函数中的拼写错误 - 已修复。
That's some crazy coding there! It's pointless accepting a size in your function, because it merely returns an array of post objects.
Once you've got your posts, then use the appropriate attachment function(s) to get the information on the attachment size you're after.
I would propose a function like this instead;
And putting it in practice;
UPDATE: Typo in function - fixed.