$args = array( 'order' => 'DESC', 'post_mime_type' => 'image', 'post_parent' => get_the_ID(), 'post_status' => null, 'post_type' => 'attachment', ); $attachments = get_children( $args ); foreach ( $attachments as $attachment ) { $output .= '<figure class="wp-block-image wp-image-'.$attachment->ID.'" style="float:left;margin-right:10px;"><img loading="lazy" src="' . esc_url( wp_get_attachment_thumb_url( $attachment->ID ) ) . '" class="wp-image-'.$attachment->ID.'" width="180" height="120" style="height:120px !important" />'; $output .= '<p style="width:180px; margin-left: 5px; font-size: 0.8rem;"><a href="'.esc_url( get_permalink()).'" title="'.esc_html(get_the_title()).'" >'.wp_trim_words(get_the_title(), 8).'</a></p></figure><!-- .wp-block-image -->'; }
参考官方文档:https://developer.wordpress.org/reference/functions/get_children/
声明:本文采用 BY-NC-SA 协议进行授权,如无注明均为原创,转载请注明转自 你好!刘
本文地址:WordPress获取文章图片附件函数get_children
本文地址:WordPress获取文章图片附件函数get_children
发表评论