bo5ton — 2012-01-30T20:28:27-05:00 — #1
I'd like to develop a wordpress site that revolves around users selecting a particular theme depending on the choise they make.
So far I've think I have come up with a solution to developing this but need some feedback before I jump in. Basically I just need to know if this is a silly way to go about it or if it might actually be feasible.
Here is a flowchart of how I believe it will work. Feel free to comment or query me.
I'm not sure if this is the right place to have this thread or not, but it involved php to begin with so I thought I would start here.
sogo7 — 2012-01-30T22:40:53-05:00 — #2
bo5ton — 2012-01-30T23:59:28-05:00 — #3
In terms of the PHP, it may be a loaded question, but is it possible to set a cookie for a wordpress theme on page load? I'm not thoroughly educated in PHP.
I would just need to use setcookie with a value depending on the image they choose?
brense — 2012-01-31T02:27:30-05:00 — #4
I would not store information about themes in cookies. Better to store that information in a database. If you are using wordpress there should already be a cookie for every user that is logged in. You can create a script that uses the id from that cookie to store information about the theme for each user.
bo5ton — 2012-01-31T16:45:42-05:00 — #5
This site won't be for users to log in. It will only be an information site and won't have a database of users.
brense — 2012-01-31T17:46:10-05:00 — #6
Imho cookies should only be used to store user specific information (login data, form data, authorizations... stuff like that.) Remember, cookies are stored on the users computer. Imho it's not polite to store data on a users computer when it is not user specific.
You could use sessions instead.
I understand though, you dont want to bother users with a login form just so your site can remember which theme they last picked.
And yes. You can set cookies with php on pageload.
bo5ton — 2012-01-31T19:39:09-05:00 — #7
I'm not sure how do to this. Can you provide any links for guidance? Would this set a theme via their IP or something?
brense — 2012-02-01T02:18:18-05:00 — #8
It would link the theme to their session id. This means that aslong as their browser is open you can see what theme they selected during that browser session. For example. If i go to your site and select a theme. Then go to google.com and later to sitepoint.com and then return to your site I still get to see the same theme. However. Once I close my browser the information disappears. Sessions are stored on the server instead of the users pc.
Working with sessions in php is very easy. The most important thing is that you must remember to start each script in which you want to use the session with:
Once you do that you can simply use the $_SESSION variable to store data:
$_SESSION['my_theme'] = 'theme_id';
Checking to see if the session exists is also straight forward:
// session exists
bo5ton — 2012-02-01T17:50:43-05:00 — #9
Thanks for that brense. (Welcome to the forums by the way, you've been very busy in the last few days I can see!)
That is helpful as it gives me an idea of what I may need to do, however the only thing that could be a problem is:
I don't think users would appreciate having to choose a theme every time they visit the site.
As far as I know the only way to have it so the user's theme is remembered even after they close their browser (without making user's login as well) is to have that information stored in a cookie.
brense — 2012-02-02T03:38:27-05:00 — #10
I was affraid you would say that.
And you are right. The only 3 ways I can think of are:
2) Have the users login
3) Link the theme to the users ip address (this is very dirty and unreliable)
So in this case cookies might be your best solution indeed.