Skip to content

Instantly share code, notes, and snippets.

@robinbastien
Last active December 7, 2016 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinbastien/079bc9410bedd1cf8035132e30aa2cd6 to your computer and use it in GitHub Desktop.
Save robinbastien/079bc9410bedd1cf8035132e30aa2cd6 to your computer and use it in GitHub Desktop.
Output a flexible field group of buttons with options
<?php
$link_type = get_sub_field('link_type');
if( $link_type && $link_type != 'none' ) :
$link_target = ( $link_type == 'external' || $link_type == 'file' ) ? ' target="_blank"' : '';
$link_text = get_sub_field('link_text');
$link_url = get_sub_field('link');
if( $link_type == 'internal' ) {
$link_text = empty( $link_text ) ? get_the_title( $link_url ) : $link_text;
$link_url = get_permalink( $link_url );
} elseif( $link_type == 'file' ) {
$link_url = $link_url['url'];
}
?>
<a href="<?php echo $link_url; ?>" class="[sectionname]__link"<?php echo $link_target; ?>><?php echo $link_text; ?></a>
<?php
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment