高级自定义字段 CSS class
Advanced custom field as CSS class
我在 ACF 中使用 WordPress,我需要使用自定义字段作为 CSS class.
的宽度
我创建了一个带有变量的动态样式:
<?php header("Content-type: text/css");
$scala = get_field('scala');
?>
#chart li .bar {
height: 10px;
background: #546a79;
width: <?php echo $scala ; ?> }
不幸的是我在页面上看不到结果,但是如果我输入一个精确的值就可以了:
<?php header("Content-type: text/css");
$scala = '60%';
?>
#chart li .bar {
height: 10px;
background: #546a79;
width: <?php echo $scala ; ?> }
显然我已经在 post 中注册了自定义值。
您能否将自定义 class 添加到要使用 post 上的自定义字段缩放的内容容器中。诸如下拉列表之类的东西,您可以将其设置为 "sixty",然后使用以下代码:
<div class="post-container <?php the_field('sixty'); ?>">
这将使 div 看起来像这样,当 class 被激活时:
<div class="post-container sixty">
然后像这样设置样式:
.post-container.sixty {
width: 60%
}
我在 ACF 中使用 WordPress,我需要使用自定义字段作为 CSS class.
的宽度我创建了一个带有变量的动态样式:
<?php header("Content-type: text/css");
$scala = get_field('scala');
?>
#chart li .bar {
height: 10px;
background: #546a79;
width: <?php echo $scala ; ?> }
不幸的是我在页面上看不到结果,但是如果我输入一个精确的值就可以了:
<?php header("Content-type: text/css");
$scala = '60%';
?>
#chart li .bar {
height: 10px;
background: #546a79;
width: <?php echo $scala ; ?> }
显然我已经在 post 中注册了自定义值。
您能否将自定义 class 添加到要使用 post 上的自定义字段缩放的内容容器中。诸如下拉列表之类的东西,您可以将其设置为 "sixty",然后使用以下代码:
<div class="post-container <?php the_field('sixty'); ?>">
这将使 div 看起来像这样,当 class 被激活时:
<div class="post-container sixty">
然后像这样设置样式:
.post-container.sixty {
width: 60%
}