Skip to content

Instantly share code, notes, and snippets.

@beovulf
Created February 2, 2016 09:46
Show Gist options
  • Save beovulf/ea218ddb41f2cc728dce to your computer and use it in GitHub Desktop.
Save beovulf/ea218ddb41f2cc728dce to your computer and use it in GitHub Desktop.
Advanced Custom Fields Image Object
<?php $count_posts = 0;
$q = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 4 ) );
if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();
$count_posts = $count_posts+1;
$obraz_wyrozniajacy = get_field('obraz_wyrozniajacy');
$size_1 = 'thumbnail';
$size_2 = 'medium';
$size_3 = 'large';
$size_4 = 'full';
$img_1 = $obraz_wyrozniajacy['sizes'][$size_1];
$img_2 = $obraz_wyrozniajacy['sizes'][$size_2];
$img_3 = $obraz_wyrozniajacy['sizes'][$size_3];
$img_4 = $obraz_wyrozniajacy['sizes'][$size_4];
?>
<?php if ($count_posts === 1): ?>
<img src="<?php echo $img_3;?>" alt="" />
<?php the_title(); ?>
<?php the_excerpt(); ?>
<?php the_permalink() ?>
<?php else: ?>
<img src="<?php echo $img_2;?>" alt="" />
<?php the_title(); ?>
<?php the_permalink() ?>
<?php endif; ?>
<?php endwhile; endif;?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment