The Golden Ratio

1.6180339887498948482045868343656381177203091798057628621354...

Some might wonder, "What the hell is that?". Well that's the golden ratio, and if you're a big Dan Brown fan, you probably already know what it is. Two entities are said to posses the golden ratio if their ratios are approximately 1:1.62. If you're wondering how did the ratio came around, I have no idea, and as far as I know, no one has a definite answer for that question. The golden ratio has fascinated people from every profession: mathematicians, architects, musicians, painters etc.

In designing, the golden ratio is special because it produces pleasing proportions. A good example would be Apple's iCloud logo.

iCloud

iCloud

Golden Ratio

Golden Ratio

I never noticed that until it was pointed out and it made me thought to myself, what if I were to incorporate the golden ratio when I'm designing web sites, how would it look like? I'm sure there are actually websites who have already done this, but having first hand experience of the whole process is what I really want. I made a simple layout, dividing portions of the site according to the ratio, and when I actually have the time to do it, I'll let you know how it turned out to be, but as for now, it's all just an idea.

Layout

Layout

Apple’s Website’s Blackout Effect: Revised

Note: For a list of revisions made, click here.

First of all, Happy Halloween to everyone, may all of your teeth rot from the gargantuan amount of candy that you will be consuming. I know I sound somewhat morbid, but the future doesn’t seem to be going to go well for me.

Well, with that said, if you’ve recently visited Apple’s website, you should’ve noticed that I made a cheap replica of their blackout effect. When I say cheap I mean it’s like those fake iPhones, similar, but not quite similar.

I tried to dissect Apple’s website source code but being the JavaScript illiterate that I am, I couldn’t find out much about the works of it. I searched on Google in hopes of finding the same effect that someone has made; But the only ones that showed up were paid ones, ranging from £5.00 to €5.99 ($8.02 to $8.35). I wasn’t going to pay for something simple like that. So I decided to make one my own. I have no prior knowledge on jQuery but how hard could it be right? In the end I took me about a day and a half to figure it out. FML

But because I hate people who charge money for simple and easy things like these, I am going to share my finding with everyone, and you will be allowed to take my code and do whatever you want with it, but I hold no responsibility if you fuck up. (Not that it’s possible as far as I know) The HTML code is validated as HTML5 and the CSS is validated as CSS 2.1. The code has been tested to be working on Safari 5.0.2, Firefox 4.0b6, Google Chrome 7.0.517.41, and Opera 10.63. I have no plans to test it on IE, but it’d be great if it works

DemoDownload (65KB)Demo [IE]Download [IE] (65KB)

Overlay HTML

The overlay is the black layer that covers the website when the fade in is executed. I created a different section just for that purpose

<section>
	<article>
		<div></div>
		<p>Happy Halloween!</p>
		<p>from seanooi.net</p>
	</article>
</section>

The empty div in line 3 is for the blackout image. In my demo, it would be the image with a left and right hand print on each side of the image. The div element is used to ensure that the image will display on Opera as well

Overlay CSS

body>section
{
	position: fixed;
	top: 0;
	left: 0;
	background-color: #000;
	width: 100%;
	height: 100%;
}

The position is set to fixed so that the background color covers the entire page and not only the viewable area of your web browser.

body>section>article>div
{
	background: url('images/demo-blackout.png');
	width: 625px;
	height: 200px;
	margin: 1em auto 0;
	display: none;
}

body>section>article p
{
	text-align: center;
	font-family: Helvetica, Verdana, Sans-Serif;
	color: #cc1100;
	font-size: 48pt;
	margin:.5em auto 0;
	display: none;
}

These 2 chunks of CSS is pretty much just positioning the image and text. But be sure that elements that you wish to fade in has to have the display: none; property in order for it to be able to fade in.

body>section>article, body>article
{
	display: none;
	width: 980px;
	margin: 0 auto;
}

These 2 tags have been set to display: none; as well to avoid the blackout images from flickering before it starts to fade in. body>article will be explained below

Main HTML

The main part of the page is just a few short lines for this demo.

<article>
	<div></div>
	<p>This is a demo mimicking <a href="http://www.apple.com">Apple's</a> blackout effect</p>
</article>

Main CSS

The body>article tag has been set to display: none; so that the page will not show before the blackout effect is ready, so we set it to fade in after the blackout effect executes.

body>article>div
{
	background: url('images/demo.png');
	width: 525px;
	height: 200px;
	margin: 1em auto 0;
}

body>article>p
{
	text-align: center;
}

Be sure that you position your page image below the blackout image so that when the blackout image fades out, it will be seen as if the image stayed.

jQuery

This is the part where I had a little difficulty with because I wasn’t literate in the language, but Google has been a big help to helping me find what I needed.

$(document).ready(function (){
	$('section').find('article').delay(1000).fadeIn(1);
	$('section').find('div').delay(1000).fadeIn(2000);
	$('section').find('p').delay(3000).fadeIn(2000);
	$('body').find('article').delay(4000).fadeIn(2000);
	$('section').delay(6000).fadeOut(2000);
});

As you can see, it’s pretty self explanatory. Take line 2 as an example

$('look for an element X').find('find the element within element X').delay(time it takes to execute the next command in milliseconds).fadeIn(time it takes to fade in in milliseconds);

In line 5 we give body>article a 4 second delay before it fades in behind the overlay layer.

That’s all there is to it. If anyone has a better way of doing the same thing I did, please do drop me a message. I will be very interested to know about it. Any comments are welcome too.

Revision

November 12, 2010:

  1. I received a request yesterday for an IE version of my code, so I have just revised and uploaded a new set of codes that are compatible with IE.
  2. The post will still be explained in HTML5, so if you decide to go with the IE version, you’re on your own. But the code should be fairly straightforward.

Comment Feature Back Again (Revised for WordPress 3.2)

When I first created this theme, I contemplated between having or not having the comment function implemented. In the end I went with a blog without the comment feature; Only the trackback function was enabled.

I initially thought the contact form was good enough as a means of communication, and that if no one knows how to use it, they don’t deserve to be using the internet. But I was told that to use the contact form for a simple comment would be overkilled. In addition to that someone asked for me to put up the comment section again. So I set out to think of ways to make my comment section different from the default layout yet fool-proof.

I thought for awhile and decided to make the comment page a separate page, meaning one whole page just for posting comments. The idea sounded easy, but it was actually more work then I expected it to be. For someone who had absolutely no prior knowledge to PHP, it was almost like making James Bond follow the law; Not impossible, just hard.

I searched online and came across a site that explained exactly what I wanted to do, but the instructions were pretty messy and static, so hopefully my version of instructions will be of use to anyone who wish to do the same.

In my version, you will be editing 5 files instead of the original posts’ 3 files, and with the link to the comments page left untouched. Files from your current theme folder will be:

  • single.php
  • functions.php
  • comments.php

The 2 other files will be from your /wp-includes directory. If you’ve just updated your WordPress script, these will be the only 2 files you need to edit. Click here to skip the themes section.

  • comment-template.php
  • link-template.php

Theme Folder

  1. First step is to go into your themes folder and open up the folder of your current theme.
  2. Open up single.php and wrap the following code around your single post syntaxes, within the loop
< ?php if (!isset($_GET['show'])) { ?>
	[single post codes here]
<?php } ?>
  1. Next, look for <?php comments_template(); ?> and replace it with the following code
<?php if (isset($_GET['show']) && $_GET['show'] == "comments") { ?>
	<?php comments_template(); ?>
<?php } ?>
  1. You can now go ahead and close your single.php file after saving your changes.
  2. Now open up your functions.php file and add the following function.
function curPageURL() {
	$pageURL = 'http';
	if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
		$pageURL .= "://";
		if ($_SERVER["SERVER_PORT"] != "80") {
			$pageURL .= $_SERVER["SERVER_NAME"].":" .$_SERVER["SERVER_PORT"] .$_SERVER["REQUEST_URI"];
		} else {
	$pageURL .= $_SERVER["SERVER_NAME"] .$_SERVER["REQUEST_URI"];
	}
	return $pageURL;
}
  1. Save your changes and open up your comments.php file and add the following code before the </form> tag, which is usually near the end of the file
<?php if (function_exists('curPageURL')) { ?>
	<input type="hidden" name="redirect_to" value="<?php echo curPageURL() ?>" />
<?php } ?>

You’re done editing your theme files. Next we’ll move on to the wp-includes directory.

/wp-includes

  1. Open up your comment-template.php file
  2. scroll to line 507. Replace #comment- with:
?show=comments#comment-
  1. Scroll to line 519. Replace #comments with:
?show=comments#respond
  1. Scroll to line 1001. Replace #respond with:
?show=comments#respond
  1. Scroll to line 1062. Replace # with:
?show=comments#
  1. Scroll to line 1113. Replace #$respond_id with:
?show=comments#$respond_id
  1. Scroll to line 1206. Replace #comment- with:
?show=comments#comment-

You’re now done with comment.template.php. Moving on…

  1. Now open up link-template.php
  2. Scroll to line 1767. Replace #comments with:
?show=comments
  1. Scroll to line 1881. Replace #comments with:
?show=comments

If everything went well and accordingly, the <?php comments_popup_link(); ?> function should now link to your comments page by appending ?show=comments#respond to your single post permalink rather than just #respond.

If any of you noticed, the trackback link that was previously under every post has been taken away. The reason for that is because I still have yet to figure out how to put trackbacks on a page by itself because posting it as a comment will be a mess and in addition to that, trackbacks have no avatars, therefore ruining my whole comment section design.

My Blog, Now iPhone Friendly

Just a few days ago I was talking to Keefe about the iPhone version of his blog and how I’m not worried about mine because of 2 reasons:

  1. I don’t have many readers
  2. I don’t know many people who uses the iPhone

Not long after our discussion, I started noticing more and more of my friends using the iPhone, mainly through Facebook, so the latter wasn’t so true anymore, and I decided to make my blog iPhone friendly as well.

My first attempt at searching online always ended up with results with “Just install <some name> plugin and you’re good to go”, which I hated. I don’t know why, but it has always been my personal preference to have it written right into the core of my theme rather than rely on a plugin. Frustrated, I quit my web browser and watched a movie instead.

During my second attempt, I found what I was looking for. No plugins, just altering my CSS file. All I had to do was to add following @media selector in my CSS file and target any elements within the curly brackets.

@media only screen and (max-device-width: 480px) {
}

We declare max-device-width: 480px because of the iPhone’s unique screen size. To style for average mobile devices, using the following selector should be sufficient.

@media handheld{
}

These methods are a nice way of enabling web developers and designers to style their websites to be mobile friendly. But occasionally, there’s bound to be some elements that just can’t be styled the way you want them to because of the original code itself being placed so ever obscurely. The way I countered this was by using a mobile detection script and adding an if/else statement in my PHP file. That way, I can rearrange all my codes for the mobile version of my site without having to temper with the original ones.

After hours of typing and clicking on the refresh button, I’m not-so-proud to unveil the iPhone version of my site.

Main Page

Main Page

Navigation Links

Navigation Links

Landscape View

Landscape View

Optimizing Websites

This question has been on my mind for quite some time already: “What makes a website a good website?” Besides that, there are other related questions that I’ve been thinking about too lately; Questions like “Why is it loading so slow?” and “Is it possible to make it load faster?” I’m no expert in anything web related, but I would like to voice out what I think and I hope that my thoughts and suggestions will be helpful to current web designers/developers, as well as those who plan to start making their own websites.

What

For now, I would just like to focus on blogs. Factors that immediately came to mind are:

  • Pictures or cute girls
  • Pictures of hot girls
  • Pictures or wannabe cute girls
  • Pictures of wannabe hot girls
  • Pictures of food (with girls posing)
  • Pictures of uncommon places (with girls posing)
  • Pictures of uncommon objects (with girls posing)
  • Childish writings by cute girls
  • Childish writings by hot girls
  • Childish writings by wannabe cute girls
  • Childish writings by wannabe hot girls
  • Fancy website designs

On the contrary, these are the factors that usually repulse readers from one’s site:

  • Pictures or males
  • Childish writings by males
  • Boring website designs

So as you can see, 7 out of the 12 factors of success I’ve just mentioned consists of pictures with girls in them, and 11 out of 12 of them are related to girls, which is pretty safe to say that pictures and girls are the main source of attraction. I like blogs with pretty pictures of girls too! Abso-fucking-lutely no doubt about that! But althought blogs with pretty pictures are somewhat aesthetically pleasing, they can come at a cost, mainly the cost of losing your readers with crappy connections, especially impatient ones with crappy connections like myself. I can’t remember the number of times I quit my web browser just because a site is taking too long to load.

Why

But occasionally when I do wait until a blog completes loading, I normally find out the reason why it’s taking forever to load just by taking a quick glance at it. These blogs have a plethora of pictures in just a single post, and vary from 5 to 10 posts on the front page. In addition to that, some of them have other fancy features like Flash headers, oversized picture headers, Flash twitter widgets, JavaScript navigational bars, videos and Flash ads to name a few.

A quick benchmark of one of these bloated sites (I shall call it blog-X) show a shocking number of items being loaded:

  • 7 Cascading Style Sheets (CSS)
  • 212 Images
  • 16 JaveScripts
  • 2 application objects

How

Blog-X has a total of 7MB+ of data to be loaded, which is fine if you have a connection of 5Mbps or more. Which means people with shitty connections, mainly Malaysia, with connection speeds that don’t justify their advertised speed of <insert fake speed here>, will suffer, and not to mention delay times and queue times, which adds up to approximately 2-3 minutes of your life drifting away, slowly, waiting for Blog-X to finish loading.

Over the years, i’ve learnt that in web designing, the most important thing to remember is loading time. Try to reduce the number of items your site loads when someone visits it. I like to assume that everyone has a slow connection; It helps to eliminate unnecessary items being loaded, mainly flash and JavaScript objects. Other ways that i’ve learnt are:

  1. Compress Cascading Style Sheets (CSS)
  2. Compress JavaScripts
  3. Optimize images

Referring back to blog-X, 7 style sheets!? Why not just put them all into 1 file? Wouldn’t it be easier to go through 1 file instead of 7 different files to find the CSS property you’re looking for?

And c’mon, 212 images?!? Do you really have to load that many? Change the number of posts that show on your front page! If you know you’re going to write a shit load of trash and upload tons of unoptimized images, then reduced it to a post, or 2 at most. No one wants to wait forever for your site to load while it’s hogging every last drop of connection speed they have. It’s just downright depressing.

Not to forget, 16 JavaScripts, consisting of a few Twitter scripts, a few web counter scripts, and a few more random widget scripts. We don’t need to know how many people visited your site, keep the numbers to yourself. We also don’t need to know when you’re going to bed, when you woke up, what you’re eating or if you’re in the shower or not. These are the type of things that your readers can live without, if not less.

One good compression script for JavaScripts and CSS I found to be very effective and easy to use is Minify. I love how you can combine like files into a single link.

If you’re using WordPress, a possible way of reducing load times is to modify your theme’s single.php file so that it displays a single post per page, while retaining the number of posts shown in your archives per page. The way to do this is to first duplicate your single.php file and rename the duplicated one to home.php. In your index.php file, paste the following code under your get_header(); line.

< ?php $wp_query->is_single = true; ?>

So it should end up looking something like this:

< ?php get_header(); ?>
< ?php $wp_query->is_single = true; ?>

Next is to open up your home.php file and paste the following code under your get_header(); line too.

< ?php
      $i=0; // Initialize to Zero;
      if (have_posts()) :
        while (have_posts()) : the_post();
            if ($i==0) {$recentpostid = $post->ID; $i=$i+1;}
        endwhile;
      endif;
      //get only the latest post
      $posts = query_posts( 'p='.$recentpostid."'");
?>

You’re done. Right now your main page should show 1 post per page in the format of single.php.

If you’re wondering why I didn’t just change the reading settings in the admin panel, it’s because if I did, the main page will indeed show 1 post per page, but if I click into my archives, it’ll also show only 1 post per page, which is really annoying if I’m trying to go through my old posts.

When it comes to uploading pictures, I like to first optimize it with Smush.itTM and post thumbnails instead of the full size, which saves on loading time and lets readers have the choice of choosing which picture they prefer to view in full size.

CSS has become so powerful now that it is capable of replacing images. If you’re using Safari 4 or Google Chrome, you should be seeing a blue gradient in my header. It’s done using CSS, not images. Same goes for the calendar on the left of this post. As mentioned in my first post, the only image I’m using for this theme is the “leafy” divider at the end of this post.

Therefore

This article my not be entirely true, but it is based on what I’ve noticed and learnt. Besides methods mentioned above, I’m sure there are other better ones available out there. If anyone would be kind enough to share, please feel free to contact me using the contact form.

New Theme, New Blog

I never have many readers to begin with, so this huge change (to me) shouldn’t be a huge problem.

To those of you who have noticed that there are no more posts other than this one, I’ve remade my blog. All old posts have been properly backed up so they’re not entirely gone for good. I may still check back my old posts as reference once in awhile.

As for this new theme I’m currently using, it’s called Tranquil. Mainly because I wanted it to be clean and minimal, giving readers a sense of tranquility. I’ve made some changes compared to standard WordPress themes.

  • It has been written in HTML5 and I’ve made pretty good use of the theme’s function.php file.
  • The sidebar has been removed with all the content moved to the top navigational bar for a bigger reading space.
  • There are no div tags, except for one that wraps the inside of the <!–[if IE]><![endif]–> conditional tag.
  • Only 1 image is used. Others are all done with the power of CSS
  • I’ve somewhat removed the footer and comments link for I see no point in having them.
  • If so happen there comes the need to contact me, I’ve made a contact form which will be used to email me.
  • Permalinks have been moved from the title of posts to the calendar at the side

The reason I cleared all my old posts is because there are countless broken links scattered all around them, which I refuse to check through each and every one of them.

Posts that I will be writing will still be random, ranging form my personal experiences to news that I find interesting. I’m hoping that this new start will be a better one than before.

Following the light of the sun, we left the Old World.

~Christopher Columbus