WordPress画廊最后一行

时间:2012-05-23 15:40:33

标签: php wordpress wordpress-theming

这是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;

1 个答案:

答案 0 :(得分:0)

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

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