$attachments = array(
'post_type' => 'portfolio',
'order' => 'ASC',
'posts_per_page' => '-1'
// 'exclude' => get_post_thumbnail_id()
);
$main_qury = new WP_Query($attachments);
$mate=$main_qury->posts;
foreach ( $mate as $attachment ) {
// $class = "post-attachment mime-" . sanitize_title( $attachment->post_mime_type );
$thumbimg = wp_get_attachment_image_src( $attachment->ID, 'thumbnail-size', true );
// echo '<li class="' . $class . ' data-design-thumbnail">' . $thumbimg . '</li>';
echo "<pre>";
print_r($thumbimg);
}
我想只获得那些没有特色的图片,但现在我正在获取包含帖子内容的图片...我如何将图片内容与图片分开...
答案 0 :(得分:3)
我不知道您为什么要尝试使用这样的WP_Query。
请改为尝试:
global $post;
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_status' => 'any',
'post_parent' => $post->ID,
'exclude' => get_post_thumbnail_id(),
) );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo wp_get_attachment_image( $attachment->ID, 'large' );
}
}
将wp_get_attachment_image()
中的大号替换为您想要使用的大小。