为了账号安全,请及时绑定邮箱和手机立即绑定

ACF 不显示 wp 主题页脚中的值

ACF 不显示 wp 主题页脚中的值

PHP
精慕HU 2023-07-08 16:34:47
这看起来很简单,但我无法让它发挥作用。我想要的只是显示一个存储为自定义字段的标题(它是 h3 标签)。我在代码中的另一个地方使用它并且它有效,但不在页脚中。ACF 是否仅在某些领域起作用,而在其他领域不起作用?<footer class="section section--footer">    <div class="section--footer__header">$post_id = get_queried_object_id();        <h3 class="text-white"><?php echo the_field("cta_field_title",$post_id);?></h3>    </div>    <form action="#" class="section--footer__form">        <div class="section--footer__input-box center">            <label for="name"></label>            <input type="text" id="name" placeholder="name" class="input">            <label for="email"></label>            <input type="text" id="email" placeholder="email address" class="input">        </div>        <div class="button__box center">            <a href="#" class="button">Submit</a>        </div>    </form>    <div class="section--footer__links">        <?php wp_nav_menu(array(            "theme_location" => "footer",            "menu" => "desktop",            "menu_class" => "section--footer__links"        )) ?>        <?php wp_nav_menu(array(            "theme_location" => "social",            "menu" => "desktop",        )) ?>    </div></footer><?php wp_footer() ?></body></html>
查看完整描述

1 回答

?
白猪掌柜的

TA贡献1893条经验 获得超10个赞

当您使用 ACF 函数获取 Wordpress“循环”之外的字段值时,您需要将帖子 id 作为第二个参数传递到函数中,例如


$post_id = get_queried_object_id(); // gets the id of the current page/post

the_field("cta_field_title", $post_id);

(仅供参考,您不需要将 echo 与the_field... 一起使用,该函数已显示该值。但是您确实需要将其与 等一起使用get_field)get_fields。


所以你的页脚看起来像这样:


<footer class="section section--footer">

    <div class="section--footer__header">

        <?php $post_id = get_queried_object_id();  /* get the current page/post id */ ?>

        <h3 class="text-white"><?php the_field("cta_field_title", $post_id);?></h3>

    </div>

    // rest of your code here

</footer>


查看完整回答
反对 回复 2023-07-08
  • 1 回答
  • 0 关注
  • 81 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信