1

I have an option in my theme settings that is made by option tree that is border type. now I want to say if that wasn't empty, set css for my div. my id of border type in option tree is header-1-border-top. when I use :

<?php print_r(ot_get_option( 'header-1-border-top' )); ?>

in my php file it shows me this:

Array ( [width] => 2 [unit] => px [style] => solid [color] => #8224e3 )

and this is where I want to set my style :

<style type="text/css">
.filmview-header-1 {
<?php if (ot_get_option( 'header-1-border-top' ) !== ''){ ?>
border-top: /*what put here?*/;
<?php } ?>
}
</style>

I don't know what should I put where I wrote /*what put here?*/ to everything work well.

6
  • developer.mozilla.org/en-US/docs/Web/CSS/border Commented Dec 31, 2017 at 15:07
  • I know the syntax of css, I don't know how to convert array to that form Commented Dec 31, 2017 at 15:10
  • ot_get_option( 'header-1-border-top')['width'] . ot_get_option( 'header-1-border-top')['unit'] . " " . ot_get_option( 'header-1-border-top')['style'] . " " . ot_get_option( 'header-1-border-top')['color'] Commented Dec 31, 2017 at 15:12
  • @connexo That did't work. And last ')' is extra Commented Dec 31, 2017 at 15:15
  • The keys of the array entries need to be passed as strings. Changed my comment above accordingly. Commented Dec 31, 2017 at 15:17

1 Answer 1

0

You need to output the the result of the option/array, for example:

<style type="text/css">
.filmview-header-1 {
<?php if (($options = ot_get_option( 'header-1-border-top' )) !== ''): ?>
    border-top: <?php echo isset($options['width']) ? $options['width'] : null,
                           isset($options['unit'])  ? $options['unit'] : null,
                           isset($options['style']) ? ' '.$options['style'] : null,
                           isset($options['color']) ? ' '.$options['color'] : null; ?>;
<?php endif ?>
}
</style>
Sign up to request clarification or add additional context in comments.

3 Comments

wouldn't imploding create a space between width and unit?
Are you sure? I got syntax error. and you miss .filmview-header-1 {}
sorry, was rushing about at home.. fixed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.