在下面的代码中,我使用get_field()显示一个Case;在我的首页上。 知道我想能够随机使用两个字段(),使用get_field('promote_case')和get_field('promote_case_two');在首页上。 当一个人更新网页时应该将这两个字段随机... 我怎么能在我的代码中做到这一点?
<?php if ( $case = get_field( 'promoted_case') ) : ?>
<?php $link = get_permalink( $case->ID ); ?>
<section class="content row">
<header class="dotted">
<h2 class="centered uc feat-case-header"><?php _e( 'Featured case', 'vvt' ) ?></h2>
</header>
<article class="promoted_case">
<div class="row case-header">
<div class="twelve columns">
<h2 class="single-case-header"><a href="<?php echo $link ?>"><?php echo esc_html( $case->post_title ); ?></a></h2>
</div>
</div>
<div class="row case-content">
<div class="columns six push_six">
<div class="frontpage_case_image">
<a href="<?php echo $link ?>"><?php vvt_post_thumbnail( 'contact_images', $case->ID ); ?></a>
</div>
</div>
<div class="columns six pull_six entry-content">
<?php echo vvt_trim_words( $case->post_content ); ?>
<div class="frontpage_case_btn">
<a class="button" href="<?php echo home_url( '/cases/' ); ?>"><?php _e( 'Show all Cases', 'vvt' ); ?> <i class="icon-arrow-right"></i></a>
</div>
</div>
</div>
</article>
</section>
<?php endif; ?>
答案 0 :(得分:0)
$fields = array('promoted_case', 'promoted_case_two');
$field = $fields[rand(0, count($fields) - 1)];
if ( $case = get_field( $field) )