My client has a website which lists 3 thumbnails, this is great but I need to get a cropped version of the thumbnail rather than the default thumbnail. The thumbnail class is called “type-one”.
<?php
$i = 0;
//$query = new WP_Query( array('category_in' => array_merge(array('6'),$subcats)) );
//$query = new WP_Query( 'post_type=page&post_parent=35&posts_per_page=3' );
$query = new WP_Query( array(
'post_type' => 'page',
'post_parent' => 35,
'post__not_in' => array( $post->ID ),
'posts_per_page' => 3
)
);
if ( $query->have_posts() ){
while ( $query->have_posts() ){
$query->the_post();
$fields = get_fields();
$i++;
?>
<div class="large-4 medium-4 small-6 columns">
<?php if( $fields['featured_image'] ) { ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><img src="<?php echo $fields['featured_image']['url']; ?>" alt="<?php echo $fields['featured_image']['alt']; ?>" class="margin-bottom" /></a>
<?php } ?>
<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
<?php echo $fields['introduction']; ?>
</div>
<?php
} // while
} // if have posts
?>
Print out the $fields array to see what you’re working with. With Advanced Custom fields there is a ‘sizes’ array on image fields –
You can use set post thumbnail size for Crop the image feature image
To be used in the current theme’s functions.php file.
Note: This function will not resize your existing featured images.
In your functions.php, paste one of these and adjust pixel width and height to your liking.
Set the default Post Thumbnail size by resizing the image proportionally (that is, without distorting it):
Set the default Post Thumbnail size by cropping the image (either from the sides, or from the top and bottom):
Hope this help you well!
Place this in function.php ,
Why are you doing code,
You can fix Thumbnail size from admin panel check this Post,
Thumbnail size from admin panel