Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save benpearson/d3db9bc9a904c0efff9d to your computer and use it in GitHub Desktop.
Save benpearson/d3db9bc9a904c0efff9d to your computer and use it in GitHub Desktop.
ACF - Loading images from Options page fields (for sidebar)
<?php
// Place in sidebar.php
// Currently loading largest image size. Add text field too?
<?php if( get_field('sidebar_items', 'options') ) : ?>
<ul class="sidebar-default">
<?php while( has_sub_field('sidebar_items', 'options') ) : ?>
<li>
<?php if ( get_sub_field('title') ) : ?>
<a href="<?php the_sub_field('link'); ?>" target="<?php the_sub_field('target'); ?>" >
<h3><?php the_sub_field('title'); ?></h3>
</a>
<?php endif; ?>
<?php $sidebar_image = get_sub_field('image'); ?>
<?php if ( $sidebar_image ) : ?>
<a href="<?php the_sub_field('link'); ?>" target="<?php the_sub_field('target'); ?>" >
<img src="<?php echo $sidebar_image['url']; ?>" alt="<?php echo $sidebar_image['alt']; ?>" />
</a>
<?php endif; ?>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment