ACF wordpress 模变量
ACF wordpress Modulo variable
我有一些代码。尝试添加 ACF filed(number) 而不是 static number
<?php $counter = 1; ?>
<?php $fff = the_field('show_ad_every_x_posts', 'option'); ?>
<?php if( $index_query->have_posts() ) : while( $index_query->have_posts() ) : $index_query->the_post(); ?>
<?php if($counter % $fff == 0 ): ?>
因此,当我保存它时,我遇到了类似 致命错误:未捕获的 DivisionByZeroError:零取模的错误
当我将 <?php $fff = the_field('show_ad_every_x_posts', 'option'); ?>
更改为 <?php $fff = 7; ?>
时
效果很好!
问题是我试图在每个 X post 之后显示广告。但我认为我的代码会将 post 替换为 ad.
这是完整的代码
<?php $index_query = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => '13', 'order' => 'DESC' ) ); ?>
<?php $counter = 1; ?>
<?php $fff = the_field('show_ad_every_x_posts', 'option'); ?>
<?php if( $index_query->have_posts() ) : while( $index_query->have_posts() ) : $index_query->the_post(); ?>
<?php if($counter % 7 == 0 ): ?>
<div class="item">
<div class="meme-card-body">
<img src="<?php the_field('ads_masonry_banner', 'option'); ?>" class="img-home-posts">
</div>
</div>
<?php else : ?>
<div class="item">
<a href="<?php the_permalink(); ?>">
<div class="meme-card-body">
<?php if(has_post_thumbnail()): ?>
<img src="<?php the_post_thumbnail_url(); ?>" alt="<?php the_title(); ?>" class="img-home-posts">
<?php endif; ?>
<h1 class="meme-title"><?php the_title(); ?></h1>
</div>
</a>
</div>
<?php endif; ?>
<?php $counter++; endwhile; else : endif; ?>
那么如何解决这个问题?
<?php $fff = the_field('show_ad_every_x_posts', 'option'); ?>
the_field
直接显示值并且没有 return 值 - 因此您在此处将“无”分配给 $fff
。
您想使用get_field
– 那个returns的值。
我有一些代码。尝试添加 ACF filed(number) 而不是 static number
<?php $counter = 1; ?>
<?php $fff = the_field('show_ad_every_x_posts', 'option'); ?>
<?php if( $index_query->have_posts() ) : while( $index_query->have_posts() ) : $index_query->the_post(); ?>
<?php if($counter % $fff == 0 ): ?>
因此,当我保存它时,我遇到了类似 致命错误:未捕获的 DivisionByZeroError:零取模的错误
当我将 <?php $fff = the_field('show_ad_every_x_posts', 'option'); ?>
更改为 <?php $fff = 7; ?>
时
效果很好!
问题是我试图在每个 X post 之后显示广告。但我认为我的代码会将 post 替换为 ad.
这是完整的代码
<?php $index_query = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => '13', 'order' => 'DESC' ) ); ?>
<?php $counter = 1; ?>
<?php $fff = the_field('show_ad_every_x_posts', 'option'); ?>
<?php if( $index_query->have_posts() ) : while( $index_query->have_posts() ) : $index_query->the_post(); ?>
<?php if($counter % 7 == 0 ): ?>
<div class="item">
<div class="meme-card-body">
<img src="<?php the_field('ads_masonry_banner', 'option'); ?>" class="img-home-posts">
</div>
</div>
<?php else : ?>
<div class="item">
<a href="<?php the_permalink(); ?>">
<div class="meme-card-body">
<?php if(has_post_thumbnail()): ?>
<img src="<?php the_post_thumbnail_url(); ?>" alt="<?php the_title(); ?>" class="img-home-posts">
<?php endif; ?>
<h1 class="meme-title"><?php the_title(); ?></h1>
</div>
</a>
</div>
<?php endif; ?>
<?php $counter++; endwhile; else : endif; ?>
那么如何解决这个问题?
<?php $fff = the_field('show_ad_every_x_posts', 'option'); ?>
the_field
直接显示值并且没有 return 值 - 因此您在此处将“无”分配给 $fff
。
您想使用get_field
– 那个returns的值。