1141 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+2 more
KarmaThemes says

Hi you guys and girls!

Thanks for wanting to help!
I got this option: http://pastie.org/3206675
to select premade backgrounds and call it with this function: http://pastie.org/3206683

Now I want to check if e.g. the first radiobutton/background of the array is selected so I can enhance the function.
Does anyone know how I can do that? I’m thinking something like if(of_get_option(‘patterns’)[1]==checked){ …

Appreciate every help,
thank you!

1504 posts LoveThemes
  • Has referred 100+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has collected 1+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+6 more
LoveThemes says
$backgrounds = array( of_get_option(‘patterns’) );
if ( $backgrounds[1] == 'true' ) :
    // do something 
endif;

Or, if you’re just trying to set a user selected background on the body:

<style type="text/css">
/* Background */
html, body { background: url(<?php bloginfo('template_directory'); ?>/img/<?php echo of_get_option('pattern'); ?>) top center!important;; }
</style>
1141 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+2 more
KarmaThemes says

Hi Scott and thanks!

Now I got this: http://pastie.org/3206893 Because it only should call the background function if the first background pattern is not selected. But like that, it seems to return false all the time because the pattern option http://pastie.org/3206896 does not work anymore.

Also, if I output this:
$background = array(of_get_option(‘patterns’,’‘)); print_r($background); I get this (no matter which background of the radiobutton array I selected):
Array ( [0] => http://karmathem.es/dev/this/wp-content/themes/this/patterns/ )

So it seems I will never be able to choose 1, which does not explain why the function will not run, since 0 != 1…

Maybe I am being blind now.

1504 posts LoveThemes
  • Has referred 100+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has collected 1+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+6 more
LoveThemes says

So basically what you require is that if no option is set then it defaults to a background that you specify, else it sets the users chosen background?

<?php

// Check if a user has set a background via the options
if ( of_get_option(‘patterns’) ) : 

// they have, so set it
    <style type="text/css">
        html, body { background: url(<?php echo of_get_option('patterns'); ?>); }
    </style>

// Nope, lets set a default one thene
else :

    <style type="text/css">
        html, body { background: url(../your/default/image.jpg); }
    </style>

endif;
?>
1141 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+2 more
KarmaThemes says

Hi Scotty, thanks for your help again!

It’s not quite like that.
The problem with the radiobutton option is that you cannot unselect it without resetting all the options which will cause a loss of all option settings. Which means I cannot check the if of get option because as soon as a background is chosen for the first time you cannot unselect it, but only select another background or reset the options, therefor the if of get option will always be true.
So the first radio button will be a “none” selection the person chooses in order to remove his custom background choice.
I need to check if the first one has been selected in order to deactivate the custom background function.

All the best

450 posts Don't be a HATER!
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+5 more
webinpixels says

I dont know ‘of_get_option’ function details, :D – are you use option framework or something?


//which mean user has made some changes
if( get_option('patterns') !== '' ){

     //first option value selected
     if( get_option('patterns') == $patternpath . '01.jpg' ){

     } else { //another option value

     }

} 
else { //do something default, if option is not set

}

I dont know if this will help you :D

good luck

1141 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+2 more
KarmaThemes says

Thank you webinpixels!
Yes, it’s the framework, so instead of get_option it’s just of_get_option (I just now realized “of” actually means “option framework”).

I tried this: http://pastie.org/3212224 But no matter which radiobutton I select it’s always “hi”.

:/

450 posts Don't be a HATER!
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+5 more
webinpixels says

do you have test the value of your option ( with print_r ), if the value is right (same with the value of radiobutton that selected) – please post it here – but if the value is not right as expected , you should check the framework function or your function which process the data into wp option table

1141 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+2 more
KarmaThemes says

I just found out if I do this: http://pastie.org/3212281 and link directly to the static URL of the image it says ‘hey’, so there probably is no way of making that dynamic since the output of the option is static.

Thanks for all your help, if anybody wants to share a brainstorm I’m thankful!

Edit: webinpixels we just had the same thought :)

1141 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+2 more
KarmaThemes says
Finally!
http://pastie.org/3212382
Thank you for bringing me on the right track you guys! Have a fantastic day :)

All the best,
Mel for KarmaThemes

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by