【问题标题】:Wordpress ACF field into a stylesheet将 Wordpress ACF 字段转换为样式表
【发布时间】:2014-12-23 09:36:52
【问题描述】:

所以,我为主题设置设置了一个自定义帖子类型,并从那里编辑了一个自定义字段用于背景颜色。

脚本读取 style.php 样式,除非我试图获取字段值。

这是我正在尝试制作的一段代码

html, body {background-color:<?php the_field('page_background_color');?>;}

查看源代码时,背景颜色值只是空白。

【问题讨论】:

  • 我假设该值是从后端添加的,而您正尝试在前端使用该设置。是这样吗?如果是,那么在编写上述代码之前,您是否在文件中写入了&lt;style&gt; 标签?
  • 我在 php 样式文件的最开始就有这个
  • 用这个替换你输入的行:&lt;?php $absolute_path = explode('wp-content', $_SERVER['SCRIPT_FILENAME']); $wp_load = $absolute_path[0] . 'wp-load.php'; require_once($wp_load); /** Do stuff like connect to WP database and grab user set values */ header('Content-type: text/css'); header('Cache-control: must-revalidate'); ?&gt;
  • 尝试在;?&gt;之间放置一个空格

标签: php css wordpress advanced-custom-fields


【解决方案1】:

当您使用 ACF 选项页面时,您必须使用字符串“选项”作为函数 get_field() 和 the_field() 的参数

试试

html, body {background-color:<?php the_field('page_background_color', 'option' );?>;}

ACF Options Documentation

【讨论】:

    猜你喜欢
    • 2017-02-01
    • 2019-10-02
    • 2020-04-04
    • 2017-12-31
    • 2017-12-09
    • 2020-10-22
    • 2015-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多