Home › Forums › General Issues › Custom Image Sizes › Reply To: Custom Image Sizes
Nope. Still doesn’t work. And yes I have registered the custom image size in the functions file.
Here is the my full code for the template page. As you can see I am querying two different images “current” and “previous”. I’ve left the query for “previous” as is and it is working (just not with the custom image size. The code you provided is now returning the links with the alt text.
<div id="scroller">
<?php $args = array(
'numberposts' => -1,
'post_type' => 'as-investments',
'meta_key' => 'investment_status',
'meta_value' => 'Current'
);
$the_query = new WP_Query( $args ); ?>
<?php if( $the_query->have_posts() ): ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="banner-logo">
<?php
$attachment_id = get_field('investment_logo');
$size = "banner-logo"; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size );
// url = $image[0];
// width = $image[1];
// height = $image[2];
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark">
<img class="investment_logo" alt="Image of <?php the_title(); ?>" src="<?php echo $image[0]; ?>" />
</a>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
<?php $args = array(
'numberposts' => -1,
'post_type' => 'as-investments',
'meta_key' => 'investment_status',
'meta_value' => 'Previous'
);
$the_query = new WP_Query( $args ); ?>
<?php if( $the_query->have_posts() ): ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div id="banner-logo">
<a href="<?php the_permalink() ?>" title="<?php printf(__('%s','rys'), get_the_title()) ?>" rel="bookmark" >
<img class="investment_logo" alt="" src="<?php $image = get_field('investment_logo'); echo($image['sizes']['medium']); ?>" />
</a>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
</div>
functions.php file:
if ( function_exists( 'add_image_size' ) ) add_theme_support( 'post-thumbnails' );
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'grid-thumb', 79, 79, true );
add_image_size( 'profile-thumb', 125, 152, true );
add_image_size( 'investment-logo', 151, 98, true );
add_image_size( 'banner-logo', 108, 70, true );
}
See attached screenshot for custom fields.
Just to note: I am calling this image in two different locations on the site. One is where the image size needs to be 151×98 (investment logo) and then again for 108×70 (banner logo). I’m not sure if it matters but in the custom fields I have the “Investment Logo” selected.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.