Variable class

Asked

Viewed 81 times

0

I have a content loop in Wordpress and within this loop I posted a gallery (also standard WP):

<?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
    <?php endwhile; ?>
<?php endif; ?>

Which generates the following HTML:

<dl class="gallery-item">
    <dt class="portrait">
        <img src=".../foto03-150x150.jpg" class="attachment-thumbnail">
    </dt>
</dl>
<dl class="gallery-item">
    ...
</dl>

The gallery has 11 images, I need each of them to have a specific class.
Ex.: Where it is written class="gallery-item" need it to be class="gallery-item1", class="gallery-item2" and so on.

  • Create a list of this class where within the class there is an identifier for each class

  • 3

    @Eduardosully I edited your question, adding (almost unchanged) the text of your comment. Obviously, you are able to write a question clearly and simply. When people ask you for more details, they are not being boring, but wanting to understand better the your problem, so as to help you. The clearer your question, the greater the chances of getting an answer.

1 answer

1

In the archive /wp-includes/media.php, look for this passage:

$output .= "<{$itemtag} class='gallery-item'>";
$output .= "
    <{$icontag} class='gallery-icon {$orientation}'>
        $image_output
    </{$icontag}>";

And add -{$id} at the end of the class. Thus:

$output .= "<{$itemtag} class='gallery-item'>";
$output .= "
    <{$icontag} class='gallery-icon-{$id} {$orientation}'>
        $image_output
    </{$icontag}>";

This causes the image position in the gallery to be used in the class name.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.