Sign up | Lost password? | Help

My Opera news » Dynamic blog designs

Dynamic blog designs

Earlier this week, community member Amnith revealed his new designs that are changing by the time of the day. If you get in at 4 p.m. you will see one theme, while if you get in at 9 a.m. you'll see a completely different theme.

This is done by a very simple process, but requires a web hosting with PHP to work. Please note that this trick is for those of you who are experienced with Web development and know what you are doing. :smile:

The basics to this is to create different stylesheets for the different themes and arrange these in a structured way. Say that you put the stylesheets in different folders, numbered or named by the different designs. For this article we have four different themes, refreshing themselves every 6th hour. Let's call the themes morning, day, evening and night.

First off, we need to decide which intervals we want the designs to be shown at. I'll define morning as the period between 0600 and 1200, day for the period between 1200 and 1800, evening as the period between 1800 and 0000, and night as the period between 0000 and 0600. Now that we have the given periods, we can start working on the different CSS files.

To structurize our script, we'll put the CSS files in their different directories, named by the different themes, and put the CSS files in these directories. We'll call all the files user.css to keep it easy to edit. We shall now have the following setup:

(root directory)

  • morning
  • user.css
  • day
  • user.css
  • evening
  • user.css
  • night
  • user.css

Bold words are directories

The user.css are the CSS files you have generated for the different themes. An excellent way to do so is to use Furie and Moesring's ingenious My Opera CSS Generator. This piece of neatness is designed to enable anyone to customize their blog themes without any specific knowledge of CSS, and allows people to change the look and feel of their pages easily.

Now that the designs are in place, we have to make the script that does the magic. The script itself is written in PHP, and its general idea is this: If the hour of the day is between X and Y, show design Z. The hour has to be in 24 hour format.

Great! Now we have a little formula to work with, and to get the hour of the day with PHP we will use this command:
$hour = date("H");

For the computer to interpret PHP, we have to wrap the script into special "tags": <?php ?>.

Now, in order for us to be able to get out the correct designs to the correct time, we will have to check to see if the hour meets the criterias we have set. Say for our night design, we want it to be shown between 0000 and 0600, while the morning takes over from 0600. This means that we will have to see if the value of the hour is greater than or equal to 0 and less than 6. This is done like this in PHP:

<?php
  $hour = date("H");
  if ( $hour >= 0 && $hour < 6 )
  {
    <do something here>
  }
?>

This is read as: if the value of hour is greater than or equal to zero and the value of hour is less than six, then...

What we want to do instead of the <do something here>, is to include and show the appropriate CSS file. This is done with PHP's include command. This is how it is done:

<?php
  $hour = date("H");
  if ( $hour >= 0 && $hour < 6 )
  {
    include "night/user.css";
  }
?>

Great job! Now we have a CSS file shown between 0000 and 0600! We are going to use the same template for the rest of the intervals, but instead of if, we're going to use elseif.

The entire code block will then be read as: if the value of hour is greater than or equal to zero and the value of hour is less than six, then include the user.css file from the night directory. Otherwise, if the value of hour is greater than or equal to six and the value of hour is less than twelve, then include the user.css file from the morning directory. This repeats for the remaining two intervals.

<?php
  $hour = date("H");
  if ( $hour >= && $hour < 6 )
  {
    include "night/user.css";
  }
  elseif ( $hour >= 6 && $hour < 12 )
  {
    include "morning/user.css";
  }
  elseif ( $hour >= 12 && $hour < 18 )
  {
    include "day/user.css";
  }
  elseif ( $hour >= 18 && $hour < 24 )
  {
    include "evening/user.css";
  }
?>

That's it, you're done! Save the script to the file "myo.php" in the root directory and go to your My Opera account page. Now, choose design and custom style sheet. In the custom style sheet page, paste the following code:
@import url("http://path.to/hosting/rootfolder/myo.php");

Congratulations! You have now made a dynamic My Opera design!

Comments

Lorenzo Celsi 27. May 2009, 14:24

It could be easily done via JS, of course if MyOpera allowed editing the blog page code. I had it on my Blogger blog some years ago but then I was too lazy to maintain more than one layout for my blog. Besides, it is already difficult to get ONE good looking layout, way too much work producing three or four. :smile:

Jamjumetley 27. May 2009, 14:26

More of tricks like this one please! :smile:

Tamil 27. May 2009, 14:27

Charles Schloss 27. May 2009, 14:46

Soumitram4u. 27. May 2009, 14:48

:up:

Blue Moon Du 27. May 2009, 15:07

thanks!!!:cheers:

Robert Jacobsen 27. May 2009, 15:12

\o/

Matt Cox 27. May 2009, 16:08

amnith is the man!

Karen 27. May 2009, 16:34

Robert flippin' pwns the PHP! :headbang:

.... 27. May 2009, 16:36

great :up:

Samuel 27. May 2009, 17:27

Woooo! I like his designs! :wink:

Pluto Vorlet 27. May 2009, 17:31

Stupid

.... 27. May 2009, 17:40

oh...why? :eyes:

Carol 27. May 2009, 17:44

:up:

Karen 27. May 2009, 17:47

Stupid? Are you flippin' insane? I mean, really. If you don't have anything nice to say, don't say anything at all. GOSH! :irked:

.... 27. May 2009, 17:48

Nerak :lol:

Karen 27. May 2009, 17:55

Meh. I cannot stand people who just HAVE to put their two negative cents in. I mean, for cryin' out loud. Robert worked hard on this and for some putz to come along and say, "Stupid"...it's simply disrespectful...and as you can tell, pisses me off! :D

.... 27. May 2009, 18:03

yeah you're right... sorry "SimplyPluto", but... stupid? I don't think it's stupid...

Nerak... :cry: I love your avatar :lol:

Robert... YOU ROCK!!! :headbang:

Roshan 27. May 2009, 18:06

Well

Karen 27. May 2009, 18:10

Thank you! It loves you, too. :D

Ninja Rojo 27. May 2009, 18:25

very cool :yes:

The Dark Furie 27. May 2009, 18:30

That's pretty damn awesome. I never thought someone would go to that trouble for a theme here. :eyes:

.... 27. May 2009, 18:31

:smile:

Robert Jacobsen 27. May 2009, 18:31

We just have to embrace those that are new to this thing called Intarwebz as well. :wink: If he wants to comment the six characters in "Stupid", he could be my guest. Hopefully other finds it more useful! :smile:

El fantasma de Opera 27. May 2009, 18:48

:faint:

The Dark Furie 27. May 2009, 18:52

Gotta disagree with that. If he can type those six letters and get them in the right order he can understand the basic principle of civility. Being new is no excuse for being a git.
:wink:

Robert Jacobsen 27. May 2009, 18:57

Furry! \o/

Oh, wait, it was Furie :-x :smile:

.... 27. May 2009, 18:58

well... he's not new... he keeps changing his account :D
By the way he's my friend... I'm sorry, i don't know what's wrong with him

Furie... calm down :D

Paulo Henrique 27. May 2009, 19:03

I agree with our friend Lorenzo. Could be easily done in Javascript. I think that should be released in the insertion of JS Myopia. It would be a new world.

Note: The problem is the insertion of malicious code.

:raider:

Jamjumetley 27. May 2009, 19:11

Come on people! If SimplyPluto wants to say it is stupid he has the right to do so... That is democracy. Of course statements like that are questionable.

The Dark Furie 27. May 2009, 19:18

This is calm. p:

Av1ez 27. May 2009, 19:20

"Useful"? Its not enough, bro... For the stupid one like me... should cAll it "wonderful", insteAd. I dont know for some other stupid users...:wink: Keep on keeping on, mAster! :up: :up: We'r proud of of U! :up:

The Dark Furie 27. May 2009, 19:20

I swear my name makes everyone think I'm angrier than I am whenever I comment. :lol:

.... 27. May 2009, 19:26

:right: angry? you? :lol: :lol: :lol: :lol:
pumpkin killer :ko:

The Dark Furie 27. May 2009, 19:40

That was Cait. :lol:

Karen 27. May 2009, 19:41

:lol: I call him "Furry", too, Robert! :lol:

:left: Not to his 'face', though. :right: Just in my head. The other personalities in there find it to be quite humorous, too! :lol:


Av1ez 27. May 2009, 19:41

Pumpkin killer is killer, bro... Reminding me to hAlloween...:smile: Keep killing, deAr...no mAtter to pumpkin. PrActice mAkes perfect, remember? :wink:

.... 27. May 2009, 19:45

:D

ERIC 27. May 2009, 20:37

:headbang:

Robert Jacobsen 27. May 2009, 20:38

By enabling JS to be inserted at My Opera, it would be far too easy to write malicious scripts that can do almost anything towards your computer or account if using a lesser secure or possibly old Web browser. Now, I don't point any fingers to neither Web browsers or user, but there are those that never updates their software and still uses applications from the last century.

I agree that it should be possible to make some dynamic content, but one cannot just include javascripts as these contain a vast amount of API to (mis)use. If there were to be made a scripting language for My Opera, it would require a specific and sandboxed API, which would neither gain access to your browser's features nor your computer.

Does this make any sense at all, or am I just rambling about random stuff? :confused:

Andrew Nguyen 27. May 2009, 21:25

:headbang:

Av1ez 27. May 2009, 22:51

U were just trying 2b humble... Well... U know it best, Boss...:wink:

Angeliki 27. May 2009, 22:54

Lailo Rafael 28. May 2009, 00:39

I like it?More power 2u ...!

Captain Falcon 28. May 2009, 02:42

could i have one in english please?
nm i'll figure it out

Karen 28. May 2009, 02:50

:lol: Holy crap, your avatar actually made me laugh audibly. Hahaha...not to mention your username. :lol: :yes:

Ivan 28. May 2009, 07:26

Nice! I'll try this stuff in near future!
Thanks men!:yes: :yes: :hat:

Robert Jacobsen 28. May 2009, 08:22

Feel free to ask me, should you have questions. :smile:

Lorenzo 28. May 2009, 10:21

I think this is a great hack but requires a web hosting with PHP to work. I agree with LorenzoCelsi.

_Grey_ 28. May 2009, 10:32

MyOpera lets us use PHP? Way cool.

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.