WordPress.org

Ready to get started?Download WordPress

Forums

Aligning the thumbnail image (3 posts)

  1. ronka
    Member
    Posted 2 years ago #

    I want to control the alignment of the featured image(the thumbnail) with the options given in the 'Set featured image' pop box.

    <?php if(has_post_thumbnail()) {
                   echo '<div class="border">'; the_post_thumbnail(); echo '</div>';
                } ?>

    I want to add to the div with the class of border a class floatleft or floatright(or nothing) according for what the user chooses.

    Thanks!

  2. maorb
    Member
    Posted 2 years ago #

    To add a class to the post's thumbnail, you should pass array of attributes to the function get_the_post_thumbnail(), see here

    So it will look something like this (I assume you are in the loop, so $post->ID will work, if not, you should handle to fetch the ID):

    <?php if(has_post_thumbnail()) {
     echo get_the_post_thumbnail($post->ID, 'thumbnail', array('class' => 'border') );
                } ?>
  3. ronka
    Member
    Posted 2 years ago #

    I can't get this to work for some reason.

Topic Closed

This topic has been closed to new replies.

About this Topic