ACF - 根据 select 值显示 div
ACF - display div based on select value
我正在尝试根据页面上 select 自定义字段上设置的值触发可变内容。如果选项 selected 是“Header standard”,则显示 div.
我使用的代码如下。任何帮助将不胜感激。
<?php $featured_post = get_field('test_header_field'); ?>
<?php if(the_field('test_header_field', $featured_post) == "Header Standard"): ?>
<div>The Content if test_header_field is equal to Header Standard.</div>
<?php endif; ?>
把你的php改成这个
<?php if( $featured_post = "Header Standard") : ?>
<div...
<?php endif;?>
您可以将代码重构为如下所示:
<?php
// grab acf field
$featured_post = get_field('test_header_field');
// set bool based on featured_post text
$is_header_standard = $featured_post === "Header Standard";
?>
<?php
// conditionally display based on previously set bool
if ($is_header_standard) : ?>
<div>The Content if test_header_field is equal to Header Standard.</div>
<?php endif; ?>
我正在尝试根据页面上 select 自定义字段上设置的值触发可变内容。如果选项 selected 是“Header standard”,则显示 div.
我使用的代码如下。任何帮助将不胜感激。
<?php $featured_post = get_field('test_header_field'); ?>
<?php if(the_field('test_header_field', $featured_post) == "Header Standard"): ?>
<div>The Content if test_header_field is equal to Header Standard.</div>
<?php endif; ?>
把你的php改成这个
<?php if( $featured_post = "Header Standard") : ?>
<div...
<?php endif;?>
您可以将代码重构为如下所示:
<?php
// grab acf field
$featured_post = get_field('test_header_field');
// set bool based on featured_post text
$is_header_standard = $featured_post === "Header Standard";
?>
<?php
// conditionally display based on previously set bool
if ($is_header_standard) : ?>
<div>The Content if test_header_field is equal to Header Standard.</div>
<?php endif; ?>