Can’t change default thumbnail size

I’m making gallery in wordpress and I want to change default thumbnail size but it doesn’t work properly. When I set photo as post thumbnail natural size is 150×150 in wordpress media options I changed thumbnail size to 215 143.

in functions I have

Read More
add_theme_support( 'post-thumbnails' );

if ( function_exists( 'add_theme_support' ) ) {
    add_theme_support( 'post-thumbnails' );
        set_post_thumbnail_size( 1240, 1240 );
}

My gallery query:

<ul id="stage">
                <?php
                // The Query
                $the_query = new WP_Query( array( 'post_type' => 'flota', 'orderby' => 'title', 'order' => 'ASC' ) );

                // The Loop
                while ( $the_query->have_posts() ) : $the_query->the_post();

                $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id ( $the_query->ID ), 'thumbnail' );
                $full = wp_get_attachment_image_src( get_post_thumbnail_id ( $the_query->ID ), 'full' );

                $cats = wp_get_object_terms( $post->ID, 'flota_category' );

                $items = array();
                    foreach ( $cats as $cat ){
                        $slug = $cat->slug;
                        $items[] = $slug;
                    }
                    $counter = count($cats);
                    $i = 0;

                ?>

                <li data-tags="<?php 
                    foreach ( $items as $tag ){
                        if (++$i === $counter ){
                            $tags = $tag;
                        }
                        else{
                            $tags = $tag . ', ';
                        }
                        echo $tags;
                    }
                ?>"><a href="<?php echo $full[0] ?>" rel="lightbox[flota]"><img src="<?php echo $thumbnail[0] ?>" width="215" height="143" style="background:#ffffff;"></a></li>

                <?php
                endwhile;               
                ?>      
</ul>

Related posts

Leave a Reply

1 comment

  1. In functions.php use:

    add_theme_support( 'post-thumbnails' );
    
    add_image_size( 'gallery-thumb', 215, 143 );
    

    Your default posts per page will be 10 which is why you can only see 10 images. Override this by changing your query to:

    $the_query = new WP_Query( array( 'post_type' => 'flota', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => -1, ) );
    

    In your query replace $thumbnail and $full with:

    $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id(), 'gallery-thumb' );
    $full      = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
    

    Then use a plugin like http://wordpress.org/plugins/regenerate-thumbnails/ to regenerate your thumbnails.

    In a loop get_post_thumbnail_id doesn’t require the ID to be set but if you do decide to set it elsewhere you were looking for $post->ID rather than $the_query->ID. Set $global $post; as well when using it.