WordPress 图库的最后一行


WordPress gallery last item of line

这里是html:

<div id="gallery-1" class="gallery galleryid-429 gallery-columns-5 gallery-size-thumbnail"> 
<dl class="gallery-item"></dl>
<dl class="gallery-item"></dl>
<dl class="gallery-item"></dl>
<dl class="gallery-item"></dl>
<dl class="gallery-item"></dl>
<br style="clear: both">
<dl class="gallery-item"></dl>
<dl class="gallery-item"></dl>
<dl class="gallery-item"></dl>
</div>

所以我在每五个项目之后都有 br style="clear: both"。有人可以帮忙如何将我的 css 类添加到第五项中吗?

这是php wp函数:

$i = 0;
foreach ( $attachments as $id => $attachment ) {
    $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
    $output .= "<{$itemtag} class='gallery-item'>";
    $output .= "
        <{$icontag} class='gallery-icon'>
            $link
        </{$icontag}>";
    if ( $captiontag && trim($attachment->post_excerpt) ) {
        $output .= "
            <{$captiontag} class='wp-caption-text gallery-caption'>
            " . wptexturize($attachment->post_excerpt) . "
            </{$captiontag}>";
    }
    $output .= "</{$itemtag}>";
    if ( $columns > 0 && ++$i % $columns == 0 )
        $output .= '<br style="clear: both" />';
}
$output .= "
    </div>'n";
return $output;

您可以使用以下 CSS 定位每五个元素:

.gallery-item:nth-child(5n+5) {
  /* css */
}