0

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>

したがって、5 番目の各項目の後に br style="clear: both" があります。この 5 番目の項目に my 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;
4

1 に答える 1

0

次のCSSを使用して、5つおきの要素をターゲットにできます。

.gallery-item:nth-child(5n+5) {
  /* css */
}
于 2012-05-23T15:49:22.043 に答える