php 有条件地显示ACF
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 有条件地显示ACF相关的知识,希望对你有一定的参考价值。
<?php if( get_field('power_source') ): ?>
<span><b>Power Source:</b> <?php the_field('power_source'); ?></span>
<?php endif;
if( get_field('batteries_included') ): ?>
<span><b>Batteries Included:</b> <?php the_field('batteries_included'); ?></span>
<?php endif;
if( get_field('blade_diameter') ): ?>
<span><b>Blade Diameter:</b> <?php the_field('blade_diameter'); ?></span>
<?php endif;
if( get_field('max_cut_depth') ): ?>
<span><b>Maximum Cut Depth:</b> <?php the_field('max_cut_depth'); ?></span>
<?php endif;
if( get_field('track_length') ): ?>
<span><b>Track Length:</b> <?php the_field('track_length'); ?></span>
<?php endif;
if( get_field('saw_track_included') ): ?>
<span><b>Saw Track Included:</b> <?php the_field('saw_track_included'); ?></span>
<?php endif; ?>
<!-- ENABLE SHORTCODE -->
function specs_shortcode(){
if( get_field('power_source') ): ?>
<span><b>Power Source:</b> <?php the_field('power_source'); ?></span>
<?php endif;
if( get_field('batteries_included') ): ?>
<span><b>Batteries Included:</b> <?php the_field('batteries_included'); ?></span>
<?php endif;
if( get_field('blade_diameter') ): ?>
<span><b>Blade Diameter:</b> <?php the_field('blade_diameter'); ?></span>
<?php endif;
if( get_field('max_cut_depth') ): ?>
<span><b>Maximum Cut Depth:</b> <?php the_field('max_cut_depth'); ?></span>
<?php endif;
if( get_field('track_length') ): ?>
<span><b>Track Length:</b> <?php the_field('track_length'); ?></span>
<?php endif;
if( get_field('saw_track_included') ): ?>
<span><b>Saw Track Included:</b> <?php the_field('saw_track_included'); ?></span>
<?php endif;
}
add_shortcode('acf_specs','specs_shortcode');
?>
<!-- SHORTCODE WOULD BE [acf_specs] -->
以上是关于php 有条件地显示ACF的主要内容,如果未能解决你的问题,请参考以下文章
php 两个简单的例子,只显示acf,如果有内容显示。
php 有条件地根据复杂的验证规则显示/要求/修改重力形式字段
php ACF代码显示带有嵌入链接的图像,后跟文本字段
php ACF代码显示带有嵌入链接的图像,后跟文本字段
Wordpress ACF php 关系
php 添加样式到wordpress admin / acf flex元框突出显示