redux-framework icon indicating copy to clipboard operation
redux-framework copied to clipboard

Returning Values

Open tonibecker opened this issue 13 years ago • 10 comments

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???

tonibecker avatar Sep 16 '13 12:09 tonibecker

You've got it. That's all you have to do.

dovy avatar Sep 16 '13 13:09 dovy

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

tonibecker avatar Sep 16 '13 13:09 tonibecker

okay sorry my mistake. Have to set global $roots inside my template now everythin is fine :)

tonibecker avatar Sep 16 '13 13:09 tonibecker

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. ;)

dovy avatar Sep 16 '13 14:09 dovy

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.

oshrib avatar Sep 17 '13 21:09 oshrib

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.

dovy avatar Sep 17 '13 21:09 dovy

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 avatar Sep 17 '13 21:09 oshrib

@oshrib It's actually set elsewhere. Yes, it does work, but not until global_variable is defined.

You can use it as is.

dovy avatar Sep 18 '13 01:09 dovy

@tonibecker Hi, can you give me code example how you fixed it?

oshrib avatar Sep 18 '13 06:09 oshrib

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';

tonibecker avatar Sep 18 '13 08:09 tonibecker