這看起來很簡單,但我無法讓它發揮作用。我想要的只是顯示一個存儲為自定義字段的標題(它是 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>
- 1 回答
- 0 關注
- 133 瀏覽
添加回答
舉報
0/150
提交
取消