I'm using ACF, flexible-content.
I have made media fields for facebook, twitter and more.
The fields will get the link, as the front-end is just the logo of the company.
I need to show the html, only if the value is set, if not, don't show it.
How can I accomplish this? I need something like this:
if( get_row_layout() == 'social_media_icons' ): ?>
if get_sub_field('media_facebook') is set, show this {
<li class="author-profile__social-item"><a rel="noopener noreferrer" href="<?php echo get_sub_field('media_facebook'); ?>" class="author-profile__social-anchor" target="_blank"><i class="fa fa-facebook" aria-hidden="true"></i></a></li>
}
if get_sub_field('media_twitter') is set, show this {
<li>Twitter</li>
}
<?php endif; ?>
I have tried this:
<?php
while ( have_posts() ) : the_post();
if( have_rows('social_media','user_'. $author_id) ):
while ( have_rows('social_media', 'user_'. $author_id) ) : the_row();
if( get_row_layout() == 'social_media_icons' ): ?>
<?php if (get_sub_field('media_facebook')) { ?>
<li class="author-profile__social-item"><a rel="noopener noreferrer" href="<?php echo get_sub_field('media_facebook'); ?>" class="author-profile__social-anchor" target="_blank"><i class="fa fa-facebook" aria-hidden="true"></i></a></li>
<?php } ?>
<?php if (get_sub_field('media_twitter')) { ?>
<li class="author-profile__social-item"><a rel="noopener noreferrer" href="<?php echo get_sub_field('media_twitter'); ?>" class="author-profile__social-anchor" target="_blank"><i class="fa fa-twitter" aria-hidden="true"></i></a></li>
<?php } ?>
<?php if (get_sub_field('media_github')) { ?>
<li class="author-profile__social-item"><a rel="noopener noreferrer" href="<?php echo get_sub_field('media_github'); ?>" class="author-profile__social-anchor" target="_blank"><i class="fa fa-github" aria-hidden="true"></i></a></li>
<?php } ?>
<?php if (get_sub_field('media_linkedin')) { ?>
<li class="author-profile__social-item"><a rel="noopener noreferrer" href="<?php echo get_sub_field('media_linkedin'); ?>" class="author-profile__social-anchor" target="_blank"><i class="fa fa-linkedin-square" aria-hidden="true"></i></a></li>
<?php } ?>
<?php if (get_sub_field('media_google')) { ?>
<li class="author-profile__social-item"><a rel="noopener noreferrer" href="<?php echo get_sub_field('media_google'); ?>" class="author-profile__social-anchor" target="_blank"><i class="fa fa-google-plus-official" aria-hidden="true"></i></a></li>
<?php } ?>
<?php if (get_sub_field('media_reddit')) { ?>
<li class="author-profile__social-item"><a rel="noopener noreferrer" href="<?php echo get_sub_field('media_reddit'); ?>" class="author-profile__social-anchor" target="_blank"><i class="fa fa-reddit-alien" aria-hidden="true"></i></i></a></li>
<?php } ?>
<?php if (get_sub_field('media_personal_website')) { ?>
<li class="author-profile__social-item"><a rel="noopener noreferrer" href="<?php echo get_sub_field('media_personal_website'); ?>" class="author-profile__social-anchor" target="_blank"><i class="fa fa-globe" aria-hidden="true"></i></a></li>
<?php } ?>
<?php endif; ?>
<?php endwhile;
else :
echo 'no content';
endif;
endwhile; // End of the loop.
?>
However, what is this, but it shows 3times each.
So it shows facebook, git,linke, facebook, git, linke, facebook, git, linke
It doesn't show those where the value isn't set.
How can I not make them repeat those who are set?
ACF Flexible Content