RSS
 

Six easy search engine optimization techniques

09 Jun

Search engine optimization (SEO) is the buzzword of now and there are a fair few companies out there that specialize in this very easy technique. Like anything, SEO is not that hard when you know where to begin.

What is search engine optimization?

SEO is a method of targeting your website to specific search terms relevant to the content of your site. So in order for you website to pop up generically in Googles top ten it needs to be relevant and “recommended” for that particular search term.

Google’s page rank algorithm, among others,  is a method that Google uses to deem which sites are the most relevant to a particular search term. It does this by working out which site has the most relevant recommendations – ie hyperlinks to it – compared to the rest. I won’t go into details of this as there is plenty of litrature on the topic if you search…. well Google, but it basically means that the more exposure your site gets the higher up in the results you will get.

How do I SEO?

SEO is easy it just takes time. If you follow the steps below and give your website time to mature on the internet then you will see it climb from one or two hits a month to multiple hits per day.

1. Relevant content is key

Before you begin you need to have a website that has content that is relevant to the topic of your website. So if you have a site about bath tubs, your need readable content about bath tubs and the link to the content to be about bath tubs! So there is no point having the link to your bath tub content – http://www.site.com/hamandchese/! The link should be something like http://www.site.com/info-on-bathtubs so the reader and search engines know that this section of the website is about bath tubs and bath tubs only! This means that when someone Googles bath tubs your bath tub site has more chance of showing up then the rest.

2. Webmaster Tools

Google has its free webmaster tools (http://www.google.com/webmasters/) that allow you to submit your website and make it known to Google. In order to use webmaster tools you will need a Google account and access to your web hosting server. Adding your website to webmaster tools will not increase its page rank but it will verify your site with Google as being legitimate website owned by a real person. This is done through a meta tag that you will need to place within the header of your website home page. Once verified the webmaster tool suite will help you distinguish how successful you website is within Google.

Another good tool to track your SEO perormance is Google Analytics (http://www.google.com.au/analytics/), also free, that give your a comprehensive suite of reporting tools giving you information on your website traffic. To use Analytics you will need a Google account and access to your website server. When you sign up with Analytics your will be given some tracking JavaScript code that will need to be placed at the bottom of each page in your website.

3. Twitter and Facebook

Love them or hate them Twitter and Facebook are here to stay and are fantastic tools to get your website known to more people and, in turn, increase its page rank. If you do not have a Twitter account and/or a Public facebook page for your website then your are missing out on two of the biggest referees on the web!

To use them effectively all you need to do is set up each of these with a little bit of info about your website and a link to it. If your website is a blog, like this one, then every time your release a blog post tweet about it. This will not only let people know about what your are doing but it will also give the Google bot one more reference to your site that may affect your page rank positively.

Remember relevance is key. If you just spam Twitter and Facebook with a whole heap of noise then your reference will be diluted and not taken as seriously as a tweet or post relevant to your site. Heard of re-tweets? If your tweet is relevant to one of your followers it might get re-tweeted a few times… how many more references to your website will be generated? This depends on the quality of the tweet and how many times it gets re-tweeted. Note: Noisy spam does not get re-tweeted.

4. Public forums and blogs

If you use forums or comment on blogs that are relevant to your website include a link to your website in your profile signature.

Note: forums don’t want your to spam their sites with your website because we all hate spam! However if your are a member of the forum or comment on a blog and have a link back to your website in a way that is acceptable to their forum or blog then it can be ok.

A good example of this is my Stackoverflow profile. I use Stackoverflow occasionally to ask and answer programming questions and my website is listed in my profile. This does not mean that I add it to every post on the site. It does, however, mean that my public profile on Stackoverflow acts as another reference to my website in the world wide web.

5. Email signatures

Every email you send to clients, friends or family should have your website in the signature. Emails are not in the pubic domain so this will not directly affect your page rank in search engines. However it will will get your website known to more people and people these days don’t really remember the full website or cant be bothered typing out all those dots and www’s! Instead they Google it. So when people Google yoursite instead of typing in www.yoursite.com.au this tells Google that your site is becoming more popular.

6. Google Maps

If your website is for a local business then register it with Google maps! This will give you exposure for localized searches. The information in this needs to be to the point, just enough for a user to be enticed enough to visit your website to find out more.

Adding a buisness to Google Maps is easy, all you need is a Google account and then go to http://www.google.com/local/add/businessCenter and click the add business link. Once you have added you business Google’s automated service will either SMS or ring the telephone number supplied in the listing to verify that it is a legitimate business.

Conclusion

It will probably take your about a couple of  hours or so to set up the points above however it is a do once and reap the rewards type of thing! Once it is done you will need to be patient and make sure your keep your content relevant to what search terms you are targeting!


 
1 Comment

Posted in SEO

 

Cross browser PHP drop down menu generator powered by JQuery and CSS.

15 May

I needed to create a drop down menu that supported all the major browsers that was generated with dynamic content. So I decided to use the tried and true unordered HTML list approach. This approach can be easily controlled with pure CSS in browsers like Chrome and Firefox, however, other browsers such as Internet Explorer cause issues so JQuery is required to force compliance across multiple platforms and browsers.

First I created this neat little class that can be used to create an object model of MenuItems that can be later serialized into a HTML unordered list. This model is basically a linked list of MenuItems where the serialize function just iterates through each object and its children converting its properties into a string.

class MenuItem {

    private $name;
    private $url;
    private $level;
    private $items;

    public function __construct($item_name, $item_lvl, $item_url = "#") {
        $this->name = $item_name;
        $this->url = $item_url;
        $this->level = $item_lvl;
        $this->items = array();
    }

    public function add_item(MenuItem $menu_item) {
        $this->items[] = $menu_item;
    }

    public function serialize() {
	$html = "";

        if ($this->level == 0) {
            $html = "<ul class=\"menu\">\n";
        }

        if (!empty($this->items)) {
            $html .= "<li class=\"{$this->get_class()} menu_arrow\">";
        } else {
            $html .= "<li class=\"{$this->get_class()}\">";
        }

        $html .= "<a href=\"$this->url\">$this->name";

        if (!empty($this->items)) {
            $html .= "</a>\n<ul class=\"{$this->get_class()}_block\">\n";
            foreach ($this->items as $menu_item) {
                $html .= $menu_item->serialize();
            }
            $html .= "</ul>\n";
        } else {
            $html .= "</a>";
        }

        $html .= "</li>\n";

        if ($this->level == 0) {
            $html .= "</ul>\n";
        }

        return $html;
    }

    private function get_class() {
        switch ($this->level) {
            case 0:
                $class = "level_zero";
                break;
            case 1:
                $class = "level_one";
                break;
            case 2:
                $class = "level_two";
                break;
        }
        return $class;
    }
}

This class makes it very easy to dynamically generate a multi tiered menu. All you have to do is create your base items and add them to the MenuItem that they belong too.

$search_links = new MenuItem("Search", 1);
$search_links->add_item(
        new MenuItem("Google", 2, "http://www.google.com")
);
$search_links->add_item(
        new MenuItem("Yahoo", 2, "http://www.yahoo.com")
);

$social_links = new MenuItem("Social", 1);
$social_links->add_item(
        new MenuItem("Facebook", 2, "http://www.facebook.com")
);
$social_links->add_item(
        new MenuItem("Twitter", 2, "http://www.twitter.com")
);

$menu = new MenuItem("Links", 0);
$menu->add_item($search_links);
$menu->add_item($social_links);

echo $menu->serialize();

The code above generates the unordered list below which, as mentioned before, can be controlled with pure CSS in the newer standards compliant browsers.

<ul class="menu">
<li class="level_zero menu_arrow"><a href="#">Links</a>
<ul class="level_zero_block">
<li class="level_one menu_arrow"><a href="#">Search</a>
<ul class="level_one_block">
<li class="level_two"><a href="http://www.google.com">Google</a></li>
<li class="level_two"><a href="http://www.yahoo.com">Yahoo</a></li>
</ul>
</li>
<li class="level_one menu_arrow"><a href="#">Social</a>
<ul class="level_one_block">
<li class="level_two"><a href="http://www.facebook.com">Facebook</a></li>
<li class="level_two"><a href="http://www.twitter.com">Twitter</a></li>
</ul>
</li>
</ul>
</li>
</ul>

The list above is controlled with the tiniest amount of CSS below. Of course the nicer you wan’t your menu to look the more CSS you will need to throw in!

ul.menu li ul {
	display: none;
}

The JQuery code I used to control the above menu is larger then it needs to be in order to make the menu support most browsers and operating systems. Many of the hacks in the script is to force Internet Explorer 6/7 to conform to the likes of Chrome and Firefox. Only the min width value needs to be set here to get your menu pop outs positioned correctly.

/* IE does not support min-width so we can get it with js since we are
 * already iterating through the items to display them.
 */
function setMinWidth(element) {
	if (element.width() < 150) {
		element.css('width', '150px')
	}
}

/* IE positoning is kinda random compared to FF, Chrome and Safari so
 * this is to force it to conform.
 */
function positionPopout(element, top) {
	element.css('display', 'block');
	element.css('top', top + "px");
	setMinWidth(element);
}

$(document).ready(function() {
	$('li.level_zero').hover(
		function() {
			var element = $('ul.level_zero_block', this);
			var top = $(this).offset().top + $(this).height();

			//Fix IE left
			element.css('left', ($(this).position().left + 2) + "px");
			positionPopout(element, top);
		},
		function() {
			$('ul.level_zero_block', this).css('display', 'none');
		}
	);

	$('li.level_one').hover(
		function() {
			var element = $('ul.level_one_block', this);
			var top = $(this).offset().top -  + $(this).height();

			positionPopout(element, top);
			setMinWidth(element);
		},
		function() {
			$('ul.level_one_block', this).css('display', 'none');
		}
	);

	$('li.level_two').hover(
		function() {
			var element = $('ul.level_two_block', this);
			var top = $(this).offset().top - ($(this).height() * 2);

			positionPopout(element, top);
			setMinWidth(element);
		},
		function() {
			$('ul.level_two_block', this).css('display', 'none');
		}
	);
});

This way of providing a drop down menu for your website is not a new idea, however I think using the MenuItem class is an elegant and easy way of dynamically generating this style of menu.

 
No Comments

Posted in JQuery, PHP

 

C# to PHP – Translating my string to object to string C# solution

26 Mar

Early this year I changed jobs where my new workplace uses PHP as its language of choice. As a academic excise I decided to translate the string to object back to string C# code I did here into PHP.

I am very impressed in how easy it was to write in PHP! Instead of using class and method attributes like I did in the C# solution, I wrote a base class to store this functionality. Therefore any class that I want to collapse into a string or be built into a model should inherit this class.

What I really like about PHP over C# is the ability to dynamically build function calls and even object declaration. You can see below that get_input_string and get_array use these language features respectively. This makes it really easy to write code that deals with anonymous classes and objects.

Here is my Template class which provides similar functionality to my static method extensions I wrote in C# here.

class Template {
    private $InputTemplate;
    private $OutputCounterLen;
    private $ArgArray = array();

    public function __construct($argArray, $input_Template, $output_counter_len) {
        $this->InputTemplate = $input_Template;
        $this->ArgArray = $argArray;
        $this->OutputCounterLen = $output_counter_len;
    }

    public function get_input_string() {
        $template = $this->InputTemplate;
        foreach ($this->ArgArray as $key => $argument) {
            $func = "get_$key";
            $val = $this->$func();
            if (strlen($val) > $argument['len']) {
                throw new Exception("Too Long!");
            }
            if (!preg_match($argument['regex'], $val)) {
                throw new Exception("Regex missmatch!");
            }
            $template = str_replace("{".$key."}", $val, $template);
        }
        return $template;
    }

    public function get_array($str) {
        $count = substr($str, 0, $this->OutputCounterLen);
        $str = substr_replace($str, "", 0, $this->OutputCounterLen);
        $arr = array();
        for ($i = 0; $i < $count; $i++) {
                $class = get_class($this);
                $obj = new $class();
                foreach ($this->ArgArray as $key => $value) {
                    $val = substr($str, 0, $this->ArgArray[$key]['len']);
                    $func = "set_$key";
                    $obj->$func(trim($val));
                    $str = substr_replace($str, "", 0, $this->ArgArray[$key]['len']);
            }
            $arr[] = $obj;
        }
        return $arr;
    }
}

Now I have a Template base class that can build a string using the objects variables based on its assigned template. Below is a class the inherits the above template and and declares the maximum length and regular expression constraints of each of the classes properties. I think this part is done more elegantly in my C# solution here because you can clearly see what constraints apply to the property because they are grouped together. As far as I know PHP does not have this functionality so I had to declare these constraints in an array in the constructor of the class.

Note: Each property must have a getter and a setter to work with the Template functions. I do miss the “{ get; set; }” of C# here.

class Foo extends Template {
    private $Bar;
    private $Baz;

    public function __construct($bar = "", $baz = "") {
        $this->Bar = $bar;
        $this->Baz = $baz;

        $argArray['bar'] = array('regex' => "/^[a-zA-Z\s]+$/", 'len' => 10);
        $argArray['baz'] = array('regex' => "/^[a-zA-Z\s]+$/", 'len' => 10);
        parent::__construct($argArray, "{bar} {baz}", 2);
    }

    public function get_bar() {
        return $this->Bar;
    }

    public function get_baz() {
        return $this->Baz;
    }

    public function set_bar($val) {
        return $this->Bar = $val;
    }

    public function set_baz($val) {
        return $this->Baz = $val;
    }
}

Finally to get your string based on the properties of Foo all you need to do is call get_input_string. The echo will print “Hello World” which is based on the template string “{bar} {baz}” declared in class Foo’s constructor.

$fooObj = new Foo("Hello", "World")
echo $fooObj->get_input_string(); //Will print "Hello World"

Also, to get an array of Foo objects from a string passed to to the get_array_method you can use the following. Sadly, this means you need to create a redundant Foo object in order to call get_array. Using PHP 5.3 I could make a static method and use the new late static binding function to get the class name, however I would also need a way of statically declaring the ArgArray containing the property constraints. So this will do for now.

$arr = $fooObj->get_array("3 One 1     One 2     Two 1     Two 2     Three 1    Three 2    ");

echo $arr[0]->get_bar(); //Will print "One 1"
echo $arr[0]->get_baz(); //Will print "One 2"

echo $arr[1]->get_bar(); //Will print "Two 1"
echo $arr[1]->get_baz(); //Will print "Two 2"

echo $arr[2]->get_bar(); //Will print "Three 1"
echo $arr[2]->get_baz(); //Will print "Three 2"

As you can see the above PHP solution is written in significantly less lines of code then its C# counterpart. There are some parts of the C# solution a prefer over the PHP solution, namely the class and method attributes. However I have to say overall I prefer my PHP solution. To be idiomatic I had to change the PHP solution quite a bit. I reckon I could take the same approach in C# and it will yield less code then the original however I still thing the PHP solution will surpass!

Oh and this post is in no way saying that PHP is better then C# all the time! I just think in this particular case it was easier and, in my opinion, a better solution in PHP.

 
No Comments

Posted in PHP