我使用 foreachattachment_image
从博客文章中打印出一个。但由于某种原因,一个按钮重复了帖子的数量,我不知道我做错了什么。
我将 sage 10 与 bootstrap 5 一起使用:
@php
$images =& get_children( array (
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image'
));
@endphp
<section class="masonry-grid">
<div class="container masonry__container">
<div class="masonry__items">
<div class="item masonry__item">
<div class="masonry__images">
@if ( empty($images) )
@else
@foreach ( array_unique($images) as $attachment_id => $attachment )
<div class="masonry__image">
{!! wp_get_attachment_image( $attachment_id, false ) !!}
</div>
@endforeach
@endif
</div>
<div class="masonry__info">
<div class="masonry__category">
{{ get_the_category( $id )[0]->name }}
</div>
<div class="masonry__title">
<a href="{{ get_permalink() }}">
{!! $title !!}
</a>
</div>
</div>
<div class="masonry__socials">
<div class="masonry__social">
<div classs="masonry__authors">
<i class="fas fa-at"></i><span class="masonry__author">@include('partials/entry-meta')</span>
</div>
<div class="masonry__views">
<i class="fas fa-eye"></i><span class="masonry__author">149 views</span>
</div>
<div class="masonry__likes">
<i class="far fa-thumbs-up"></i><span class="masonry__author">8 likes</span>
</div>
</div>
</div>
</div>
</div>
<div class="masonry__buttons">
<div class="masonry__loadmore">
<button type="button" class="masonry__button btn btn-outline-secondary"><i class="fas fa-spinner"></i>Load more</button>
</div>
</div>
</div>
</section>
我打算显示多个项目和一个按钮,但是,与我期望的行为不同,显示的按钮数量与项目数量一样多。