我通过ACF插件使用图像URL创建了一个图像字段。此字段显示在我的页面中。此字段允许管理员更改选定类的背景图像。
这是我在<head></head>
标签:
<?php
while ( have_posts() ) : the_post();
$background = get_field(\'background\'); ?>
<style>
.site-header {
background: url(<?php echo $background; ?>) no-repeat center;
background-size: cover;
}
</style>
<?php endwhile; // end of the loop.
?>
通过源,url显示为空。我做错了什么?我知道ACF不能在循环之外工作,这就是为什么我在
<head>
.
以下是ACF导出:
if( function_exists(\'acf_add_local_field_group\') ):
acf_add_local_field_group(array (
\'key\' => \'group_560e6c0620487\',
\'title\' => \'Header Background\',
\'fields\' => array (
array (
\'key\' => \'field_560e6c0ed9ca8\',
\'label\' => \'Background Image\',
\'name\' => \'background\',
\'type\' => \'image\',
\'instructions\' => \'\',
\'required\' => 0,
\'conditional_logic\' => 0,
\'wrapper\' => array (
\'width\' => \'\',
\'class\' => \'\',
\'id\' => \'\',
),
\'return_format\' => \'url\',
\'preview_size\' => \'thumbnail\',
\'library\' => \'all\',
\'min_width\' => \'\',
\'min_height\' => \'\',
\'min_size\' => \'\',
\'max_width\' => \'\',
\'max_height\' => \'\',
\'max_size\' => \'\',
\'mime_types\' => \'\',
),
),
\'location\' => array (
array (
array (
\'param\' => \'page_type\',
\'operator\' => \'==\',
\'value\' => \'top_level\',
),
),
),
\'menu_order\' => 0,
\'position\' => \'normal\',
\'style\' => \'default\',
\'label_placement\' => \'top\',
\'instruction_placement\' => \'label\',
\'hide_on_screen\' => \'\',
\'active\' => 1,
\'description\' => \'\',
));
endif;