Returning Values
Hy everybody i'm starting using redux for a new client theme. So i'm using roots as the basis and copied this into functions.php if(!class_exists('ReduxFramework')){ require_once(dirname(FILE) . '/options/framework.php'); } require_once(dirname(FILE).'/options/sample/sample-config.php');
Everything is fine see the values ecetera. Now i want to retrieve the value from slider1. I defined opt_name with roots_opt. So i could acces via global var $roots_opt['slider1'] the value???
You've got it. That's all you have to do.
hmmm not working for me :/.
<?php
echo "<div style='height: 20px; background: red;'>";
echo $roots['slider1'];
echo '</div>';
?>
'')); ?>
This is the sub-template from roots-theme but no value from slider is echoed
okay sorry my mistake. Have to set global $roots inside my template now everythin is fine :)
If you have it inside a function you have to declare the global nature of the variable. I'm glad it's working for you. ;)
I have same issue, but not understand how to fix that. where to use global?
my opt_name is 'data', and i have next: array( 'id'=>'logo_image', 'type' => 'media', 'title' => __('Logo image', 'redux-framework'), 'subtitle' => __('Upload any media using the Wordpress native uploader', 'redux-framework'), ),
i want to display 'logo_image' in my header.php , and i tried this way: echo $data['logo_image'] but its not working.
Take a look here: https://github.com/ReduxFramework/ReduxFramework/issues/22
This is the tidbit you need to know:
Now a word about this global set variable. It is equal to the opt_name you set for your theme OR the name of the $args['global_variable'] you set.
Let's say for example your opt_name is theme_ten. Then if global_variable isn't set, your variable is $theme_ten. If you set your global_variable arg to say iamcool, your global variable is then $iamcool.
Thanks for your replay. Maybe its the late hour here, but.... global_variable on framework.php isnt set:
$defaults['global_variable'] = '';
i just set the opt_name in my options.php: // Set a custom option name. Don't forget to replace spaces with underscores! $args['opt_name'] = 'data';
Lets say i use the framework after fresh install without change nothing, which variable i need to use to display values?
@oshrib It's actually set elsewhere. Yes, it does work, but not until global_variable is defined.
You can use it as is.
@tonibecker Hi, can you give me code example how you fixed it?
Okay here's my setting. I'M using roots theme and copied all the files to options inside the themefolder. Than in functions.php i have this code.
require_once locate_template('/lib/custom.php'); // Custom functions if(!class_exists('ReduxFramework')){ require_once(dirname(FILE) . '/options/framework.php'); } require_once(dirname(FILE).'/options/sample/sample-config.php');
Please note the call of custom.php here i have my options output and did it that way:
<style type="text/css">
body {
background: url('<?php echo $roots['patterns']; ?>') <?php echo $roots['bgrepeat']; ?>;
font-family: <?php echo $roots['bodyfont']['family']; ?>;
font-size: <?php echo $roots['bodyfont']['size']; ?>px;
font-style: <?php echo $roots['bodyfont']['style']; ?>;
color: <?php echo $roots['bodyfont']['color']; ?>;
line-height: <?php echo $roots['bodyfont']['height']; ?>px;
}
Next step is to call the hook for printing out the inlinestyles and i do that inside the functions.php
add_action( 'wp_head', 'mytheme_dynamic_css' );
Thats all. You have to keep in mind to set the globals $your_var.
You can set your var inside the the sample_config.php and change this line to your needs:
// Set a custom option name. Don't forget to replace spaces with underscores! $args['opt_name'] = 'roots';