admin管理员组文章数量:1129796
My home page uses ACF ("settings home") fields. These fields position the items in the footer. The problem is that they don't display on other sites. How to display fields from the home page on all subpages? So that you do not have to enter the same data on each subpage
To display in footer.php I'm using:
<?php the_field('contact_form_title'); ?>
My home page uses ACF ("settings home") fields. These fields position the items in the footer. The problem is that they don't display on other sites. How to display fields from the home page on all subpages? So that you do not have to enter the same data on each subpage
To display in footer.php I'm using:
<?php the_field('contact_form_title'); ?>
Share
Improve this question
asked Feb 4, 2021 at 15:24
SimonSimon
235 bronze badges
2 Answers
Reset to default 1ACF's the_field()
and get_field()
accept several parameters, one of which is a post ID. So, you just need to get the ID of the page the field is on, like this:
<?php
$frontpage_id = get_option( 'page_on_front' );
the_field('contact_form_title', $frontpage_id);
// For pages other than home
$page = get_page_by_path('some-page-slug');
the_field('contact_form_title', $page->ID);
?>
If you have the Pro version of the plugin, you might be better to use an ACF Options Page.
More info: https://www.advancedcustomfields.com/resources/options-page/
You'll need to enable it in your theme by adding something like this to your functions.php file.
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Theme General Settings',
'menu_title' => 'Theme Settings',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
}
Then you can pop this into your footer;
<?php the_field( 'field_name', 'option' ); ?>
However you should be weary of the the fact that this will be another database query, so if you're worried about speed then it might be better to hard code the content into footer.php
At this moment in time, Options pages are only in the Pro version of the plugin I believe.
本文标签: phpHow to display acf field values from home page on all pages
版权声明:本文标题:php - How to display acf field values from home page on all pages? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736754190a1951197.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论