286 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+3 more
AkinGn says

...But I still can’t change the logo background color and the body background independently. One of them has to be default, I can’t view an alternative bg with an alternative logo-bg. I created two sessions, one for the logo background:

<?php $_SESSION['logoBgColor'] = 'yellow';
if(isset($_GET['logoBgColor'])) 
    $_SESSION['logoBgColor'] = $_GET['logoBgColor'];
?>

<link href="&lt;?php bloginfo('template_url'); ?&gt;/css/logo-bg-&lt;?php echo $_SESSION['logoBgColor']; ?&gt;.css" rel="stylesheet" type="text/css" media="all" /

and one for the body background:

<?php $_SESSION['background'] = 'style';
if(isset($_GET['background'])) 
    $_SESSION['background'] = $_GET['background'];
?>

<link href="<?php bloginfo('template_url'); ?>/css/<?php echo $_SESSION['background']; ?>.css" rel="stylesheet" media="all" type="text/css" />

but as I said, when I change one of them, the other one falls back to default. How do you guys resolve that issue?

574 posts Themes and Graphics
  • Has been part of the Envato Community for over 5 years
  • Has referred 50+ members
  • Has sold $250,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+9 more
Bebel says

Well, you should not override the session ;) Don’t use

<?php $_SESSION['color'] = 'red';
if(...)
</pr?>

but instead, first check if the session is set and if not, set it to red.
1012 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+6 more
wizylabs says
Well, you should not override the session ;) Don’t use
&lt;?php $_SESSION['color'] = 'red';
if(...)
</pr?&gt;

but instead, first check if the session is set and if not, set it to red.

So will it be something like below?

<?php if(!isset($_SESSION['color'])) {
    $_SESSION['color'] = 'red';    
} else {
    if(isset($_GET['color']))
        $_SESSION['color'] = $_GET['color'];    
}

?>

<link href="<?php bloginfo('template_directory'); ?>/css/<?php echo $_SESSION['color']; ?>.css" rel="stylesheet" media="all" type="text/css" />
574 posts Themes and Graphics
  • Has been part of the Envato Community for over 5 years
  • Has referred 50+ members
  • Has sold $250,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+9 more
Bebel says
Well, you should not override the session ;) Don’t use
&lt;?php $_SESSION['color'] = 'red';
if(...)
</pr?&gt;

but instead, first check if the session is set and if not, set it to red.

So will it be something like below?

<?php if(!isset($_SESSION['color'])) {
    $_SESSION['color'] = 'red';    
} else {
    if(isset($_GET['color']))
        $_SESSION['color'] = $_GET['color'];    
}

?>

<link href="<?php bloginfo('template_directory'); ?>/css/<?php echo $_SESSION['color']; ?>.css" rel="stylesheet" media="all" type="text/css" />

Almost. Look again at the code – what if you just set a session, but want to override the before the last session expires. :)

286 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+3 more
AkinGn says

So, what does the exact code have to be? :)) Tnx for sharing your experience with me and each other guys, I appreciate it.

574 posts Themes and Graphics
  • Has been part of the Envato Community for over 5 years
  • Has referred 50+ members
  • Has sold $250,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+9 more
Bebel says

I could post it, but then you wouldn’t learn it as good as if you tried by yourself, right? How about, I post now just some pseudo code and you try to get it by yourself. If you still fail, I will post the solution, ok? :)

Pseudo code
check if session is set
if so, check if new color is requested via get {
    if requested, set the color
    if not, 
}
if not, get default color

include css

Of course this is only one of many possible solutions :)

286 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+3 more
AkinGn says

Thanks so much Wizylabs, I tested the code you posted and it can change different elements’ style seperately :)

I could post it, but then you wouldn’t learn it as good as if you tried by yourself, right? How about, I post now just some pseudo code and you try to get it by yourself. If you still fail, I will post the solution, ok? :) Pseudo code
check if session is set
if so, check if new color is requested via get {
    if requested, set the color
    if not, 
}
if not, get default color

include css
Of course this is only one of many possible solutions :)

And Bebel, not being a php coder and looking previous posts, it has to start with something like :

<?php if(isset($_SESSION['color'])) 
     if(isset($_GET['color'])) {
        $_SESSION['color'] = $_GET['color']; 
     }
     $_SESSION['color'] = 'red'; 
?>     
<link href="<?php bloginfo('template_directory'); ?>/css/<?php echo $_SESSION['color']; ?>.css" rel="stylesheet" type="text/css" media="all" />

Yes, it doesn’t work and it’s obvious I don’t have php experience lol

574 posts Themes and Graphics
  • Has been part of the Envato Community for over 5 years
  • Has referred 50+ members
  • Has sold $250,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+9 more
Bebel says

I got the point that you are not a experienced php coder, but if you want to publish a template on themeforest, you have to know some, or am I wrong? Was your theme coded by another person? :)

Yeah, your code does not work because you, again, override your session at every request.

&lt;?php if(isset($_SESSION['color'])) // missing {, the syntax without { only works for ONE following line!
     if(isset($_GET['color'])) {
        // if the session is set and the color comes from the url, set it in session
        $_SESSION['color'] = $_GET['color']; 
     }
     // if the session is set, set it to red !!! PROBLEM IS HERE !!!
     $_SESSION['color'] = 'red'; 
// missing }
?&gt;  

See the comments, where the problem is. You ALWAYS set the session to red if the session is set..

&lt;?php if(isset($_SESSION['color'])) {
     if(isset($_GET['color'])) {
        // if the session is set and the color comes from the url, set it in session
        $_SESSION['color'] = $_GET['color']; 
     }
}else {
  if(isset($_GET['color'])) {
    $_SESSION['color'] = $_GET['color']; 
  }else {
    $_SESSION['color'] = 'red'; 
  }
}
?&gt;  

This would be one solution. But its not pretty, so what about this one?

<?php // to at least have SOME security, don't take any variables unfiltered..

$allowed_colors = array('red', 'blue', 'green'); // add your colors...

$color = isset($_GET['color']) && isset($allowed_colors[$_GET['color']) ? $_GET['color'] : 'red'; // if the color is set via get and if it is in the allowed colors list, set the color from request, otherwise set default color (red)

$_SESSION['color'] = isset($_GET['color']) ? $color : isset($_SESSION['color']) ? $_SESSION['color'] : 'red'; // if the get var does exist, get the color from $color, otherwise renew the session, if exists, or set the color to red.
</pr?>

Please note this solution was coded in the post textarea and is NOT tested. :)
286 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+3 more
AkinGn says
I got the point that you are not a experienced php coder, but if you want to publish a template on themeforest, you have to know some, or am I wrong? Was your theme coded by another person?

Good point :) All my themes are coded by me. When I decided to release some WP themes, I wanted to hire a WP coder, but I couldn’t find anyone who already has at least a WP theme / site online (they were all busy) and decided to learn and do it by myself. So, now I can code html/css, WP but apparently I better to learn some php, thanks (and some jquery/js to create custom scripts would be nicer too) :)

Looking your code, I can say the biggest lack of the snippet I wrote is syntax. But I have a question, it works like this too:

<?php if(isset($_SESSION['color'])) {
     if(isset($_GET['color'])) {
        $_SESSION['color'] = $_GET['color']; 
     }
}else {
   $_SESSION['color'] = 'red'; 
  }
?>

And this code is “one if condition less” so it’s lighter. I couldn’t get the problem with this one? (If you stated it above sorry :))

And the final snippet you posted, thank you very much for sharing the solution, as you guess it has some syntax issues and it doesn’t work. But thanks a lot again :))

574 posts Themes and Graphics
  • Has been part of the Envato Community for over 5 years
  • Has referred 50+ members
  • Has sold $250,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+9 more
Bebel says
I got the point that you are not a experienced php coder, but if you want to publish a template on themeforest, you have to know some, or am I wrong? Was your theme coded by another person?

Good point :) All my themes are coded by me. When I decided to release some WP themes, I wanted to hire a WP coder, but I couldn’t find anyone who already has at least a WP theme / site online (they were all busy) and decided to learn and do it by myself. So, now I can code html/css, WP but apparently I better to learn some php, thanks (and some jquery/js to create custom scripts would be nicer too) :)

Looking your code, I can say the biggest lack of the snippet I wrote is syntax. But I have a question, it works like this too:

<?php if(isset($_SESSION['color'])) {
     if(isset($_GET['color'])) {
        $_SESSION['color'] = $_GET['color']; 
     }
}else {
   $_SESSION['color'] = 'red'; 
  }
?>

And this code is “one if condition less” so it’s lighter. I couldn’t get the problem with this one? (If you stated it above sorry :))

And the final snippet you posted, thank you very much for sharing the solution, as you guess it has some syntax issues and it doesn’t work. But thanks a lot again :))

Well, coding is nothing else than putting your logical thoughts into code. Think about what you have to do, think about what steps you have to check – first without code. Try to find holes in your thoughts and in your model, improve it step by step – thats how all begins when you start coding. After a while it will become easier and faster. But at the beginning it is good to take some time.

As I stated above in my second example, you should never take any values from an user (via get, post or generally request, ..) unfiltered. NEVER trust your users :)

In your code, you miss the possibility: What, if the session is not set but the user wants to change the color? Like if I don’t click on your preview link first and then change the color, but directly access http://yoursite.net/?color=blue. Thats why your code is a bit lighter than mine :)

For the errors: sorry, yeah, I coded it like 10 min after breakfast in the themeforest forum textarea :P You can try to fix it by yourself, then you will become familiar with php errors :D

by
by
by
by
by
by