April 13, 201313 yr hey guys, i want to apologise in advance for being very broad, with little understanding about php its a bit confusing as to what to search! i have spent alot of my time, working on personal themes and variouis other things, along the way ive created some really nice magento themes! the problem is that i see 90% of the popular themes have some sort of control panel for users to easily change colours / styles etc. my question is, how is this being done? obviouslly on the actual page, all that is being loaded is 'calling' the php variable / function but thats it, How is php storing the different options & where? i understand the information is stored in a variable, but where? the database? How do you assign an options and then assign them to your variable? sorry again, my understanding of php is grim, javascript i have down! Thanks guys
April 13, 201313 yr Hey there My ore prerequisite is I only have experience with Wordpress. With Wordpress try looking at the theme customisation Api - with that you can get all of the colours etc that you want in the settings section. With little php experience though you may find it more difficult. Good luck!
April 13, 201313 yr Author hi ben, i learn really fast, ive been at this 10 months and as many of you will tell you here im lightyears ahead of where i should be.. Throw me a bone and let me know the basics and ill soon know what to search for and piece it together myself Best way to learn to get to my hands dirty Andy EDIT: highly experianced in jquery + js so i got the basics of how programming works, its just a case of figuring it out in php, as its more about arrays and such Edited April 13, 201313 yr by webcanvasdesign
April 14, 201313 yr I've not done this before and I mostly handcode - you can store the variables/options in an array or a database. Depending on the option entered, you could pull in a different css file. Using an array would be faster. Set up a configurations file, which every page includes. In the configurations file you can create a function that will define the array of options and actions and return to the calling page which action (or stylesheet) to pull in. When you call the function be sure to do so with a variable assignment statement to have access to the returned variable. Let me know if you need an example.
April 18, 201313 yr Author hey g, sorry for the long reply, been swamped. If you could provide a short example that would be amazing! i find it hard to learn by reading, i have to do and figure out some issues in between thanks mate
April 19, 201313 yr Ok there are several steps and I've simplified the process. I've used sessions to allow the chosen stylesheet to be accessed by all the pages. Knowing javascript you'll be familiar with sessions. Look in the php manual for the syntax - the main thing is to ensure you start the session with session_start() as the absolute first thing on pages that use the $_SESSION variable. If not, you will get an error. 1. In your configuration or functions file define the function function set_stylesheet($colour) { $styles_file=array('blue'=>'blueStyles.css', 'red'=>'redStyles.css', 'green'=>'greenStyles.css'); return $styles_file[$colour]; } 2. In your html page, you can have a mini form to allow the user to select the colour. The form action will call the set_stylesheet function and store it in a session. e.g. <?php session_start() ?> <!DOCTYPE html> <head> ... </head> <body> $colours = array('blue', 'red', 'green'); if (isset($_POST['colour']) && in_array($_POST['colour'],$colours)) { $_SESSION['stylesheet'] = set_stylesheet($_POST['colour']); } ?> <form action="" method="post"> <select name="colour"> <?php foreach ($colours as $colour) { echo '<option value="' . $colour . '">' . $colour . '</option>'; } ?> <input type="submit" value="Choose colour" /> </select> </form> 3. The head section of your pages will access the session variable to pull in the appropriate stylesheet. <?php session_start() ?> <!DOCTYPE html> ... <head> if ($_SESSION['stylesheet']) { echo '<link href="' . $_SESSION['stylesheet'] . '" rel="stylesheet" type="text/css"/>'; } else { echo '<link href="default.css" rel="stylesheet" type="text/css"/>'; } ?> </head> I have limited experience working with cms sites so you will need to alter the above to suit your cms. And for themes you might want to store the value in a configurations table rather than a session. Hope this helps.
April 19, 201313 yr Author thanks for the breakdown, i can really see how the code it working, storing variables & then calling in via html page.I shall get to work!
Create an account or sign in to comment