我正在使用 ACF,灵活的内容。
我为 facebook、twitter 等创建了媒体字段。
字段将获得链接,因为前端只是公司的徽标。
我需要显示html,只有设置了值,否则不显示。
我怎样才能做到这一点?我需要这样的东西:
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; ?>
我试过这个:
<?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.
?>
然而,这是什么,却每人显示3次。
所以它显示了 facebook,git,linke,facebook,git,linke,facebook,git,linke
它不显示未设置值的那些。
我怎样才能不让他们重复那些已经设定好的?
ACF 灵活内容