• <?php
    $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID );
    $attachments = get_posts($args);
    if ($attachments) {
    	foreach ( $attachments as $attachment ) {
    		echo '<li class="venthumb">';
    		the_attachment_link( $attachment->ID , $thumbnail, false );
    		echo '';
    	}
    }
    ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • Was there a question in there?

    Thread Starter unknownmale

    (@unknownmale)

    Sorry. I want to be able to add a class to the <a> which is outputted by this code.

    Thread Starter unknownmale

    (@unknownmale)

    This is what is output…

    <li class="venthumb"><a href='https://www.example.com/1.jpg' title='img'><img width="155" height="89" src="https://www.example.com/1.jpg" class="attachment-thumbnail" alt="img" title="img" /></a>

    And I would like this:

    <li class="venthumb"><a href='https://www.example.com/1.jpg' title='img'><img width="155" height="89" src="https://www.example.com/1.jpg" class="attachment-thumbnail" alt="img" title="img" /></a>

    Those 2 code snippets are identical.

    Thread Starter unknownmale

    (@unknownmale)

    The second should be:

    <li class="venthumb"><a href='https://www.example.com/1.jpg' title='img' class="classname"><img width="155" height="89" src="https://www.example.com/1.jpg" class="attachment-thumbnail" alt="img" title="img" /></a>
    Moderator keesiemeijer

    (@keesiemeijer)

    Try it with something like this

    if ($attachments) {
    	foreach ( $attachments as $attachment ) {
    		echo '<li class="venthumb">';
    		$img = wp_get_attachment_image( $attachment->ID, 'thumbnail', false );
    		$img_url = wp_get_attachment_url( $attachment->ID );
    		$img_title = esc_attr($attachment->post_title);
    
        echo '<a href="'.$img_url.'" title="'.$img_title.'" class="classname">'.$img.'</a>';
    		echo '';
    	}
    }

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to add a class to the’ is closed to new replies.