change Element with custom field – not working
-
I want to change the background-proberty value of an element (div id = Box2)
what sits in a container div with red background.Box2 should has a background attribute of the specified post-metakey/custom field value.
When I insert the normal php set of the customfield to show off to the footer.php it shows all the different used values of the specied article.
The stylesheet is a style.css.php file. I tried 4 Versions and all do not work.
What do i do wrong?
/* –V1 (style.css.php)-(this is working) — – – – – – – – – — – */
<?php
header(‘Content-type: text/css’);
$newBG = “darkviolet”;
?>#Box2 {
background: <?php echo $newBG ?> ;
}#Box2 {
background:red
}/* –V2 (style.css.php)- — – – – – – – – – — – */
<?php
header(‘Content-type: text/css’);
$newBG = get_post_meta($post->ID, ‘custombg’, true);
?>#Box2 {
background: <?php echo $newBG ?> ;
}#Box2 {
background:red
}/* –V3 (style.css.php)- — – – – – – – – – — – */
<?php
header(‘Content-type: text/css’);
?>#Box2 {
background: <?php the_field(‘custombg’) ?> ;
}#Box2 {
background:red
}/* –V4 (style.css.php)- — – – – – – – – – — – */
<?php
header(‘Content-type: text/css’);
?>#Box2 {
background: <?php echo the_field(‘custombg’) ?> ;
}#Box2 {
background:red
}/* –WP Check (all works fine)- — – – – – – – – – — – */
<?php the_meta();?> /* gives out every post-meta-key + values */
<br><br>
<?php echo get_post_meta($post->ID, ‘custombg’, true); ?> /* gives out specified post-meta-key + values */
<br><br>
<?php the_field(‘custombg’); ?> /* gives out specified post-meta-key value *//* –PHP/HTML values to inject- — – – – – – – – – — – */
<div id=”Box1″ style=”background:red”>
<div id=”Box2″>
</div>
</div>
- The topic ‘change Element with custom field – not working’ is closed to new replies.