Archive | Tutorials

30 June 2011 ~ Comments Off

WordPress Multi-Site Support for WooThemes

I was setting up a new multi-site in the early hours of the morning and I noticed that when a WooThemes theme is active on another blog, the link to ‘Update Framework’ was still showing under the theme options. I thought too my self that this was wrong and it would allow any one to update the framework for that theme without permission of the proper administrator of the main site.

So I did a little research on how to detect the main site and the first blog. If both equal as One then the link to update the framework would show. Otherwise any other site created using the theme it would not. This also applies to the admin bar.

Here is what I changed and is fairly easy to do your self if setting up a multi-site with WooThemes.
You will need to make a backup of two files in the WooThemes theme you are sharing.
‘admin-interface.php’ and ‘admin-functions.php’

Please not that if you update the framework after this modification it could be very well removed. If you are sharing just the one WooTheme like I am on a multi-site, then this will be easy and done in no time at all. If you are sharing more than one or all of the themes… then it will take you sometime unless all themes have the exact same framework version from the start before modifying them.
[...]

Continue Reading

01 June 2011 ~ 2 Comments

Creating a Shortcode

I finally learned how to create a proper shortcode for WordPress and now capable of creating loads of great shortcodes for my framework Ocean Themes.

This is one of the first shortcodes that I have created and will be included in the framework and thought I share with you on how you can create your own using my own as an example.
[...]

Continue Reading

03 April 2011 ~ Comments Off

Backing up your MySQL Database using PHP

Backing up your database is the far most important thing that you need to do. With out it your site does not work and loosing all of that data is a night mare. Most of the time you forget about backing up your database because you don’t regularly login to your web host account to do so unless there is a problem with your site or you need to tweak something on the server.

Show »

Well I have created a cron-job script that you can setup on your web host that will back up your database for you.

[...]

Continue Reading

23 March 2011 ~ Comments Off

Read and Fetch Hidden File Data

Ever wanted to fetch data from a file that is hidden if you were to access the file directly, well here is a piece of code that can do just that. You can display the information any where you want once the data has been fetched.

First of all you will need to copy two functions in to your website that will be called.

The first one opens the file you have asked the function to read in read only mode. This function reads the very top of the file for the headers you have in place. These headers must match the default headers you have set in the second function.

// This gets file data when called and reads the file in read only.
function get_file_data($file, $default_headers){
        // Just open for reading.
        $fp = fopen($file, 'r');

        // Pull only the first 8kiB of the file in.
        $get_data = fread($fp, 8192);

        // PHP will close file handle, but we are good citizens.
        fclose($fp);

        foreach($default_headers as $field => $regex){
                preg_match('/'.preg_quote($regex, '/').':(.*)$/mi', $get_data, ${$field});
                if(!empty(${$field})){
                        ${$field} = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', ${$field}[1]));
                }
                else{
                        ${$field} = '';
                }
        }

        $get_data = compact(array_keys($default_headers));

        return $get_data;
}

The second will need adjusting to what information you would like to fetch from that file. The headers can be what ever you want as long as you make sure the header is the same as the default headers in the function.

// This fetches the file data and returns back the information received.
function fetch_file_data($file){
        $default_headers = array(
                'Name' => 'Name',
                'Email' => 'Email',
                'URI' => 'URI'
        );

        // This calls the other function to read the headers from the file specified.
        $file_data = get_file_data($file, $default_headers);

        $file_data['Name'] = $file_data['Name'];
        $file_data['Email'] = $file_data['Email'];
        $file_data['URI'] = $file_data['URI'];

        return $file_data;
}

How do I use these functions?
You simply use the ‘fetch_file_data’ function and echo in place were you want to display the data from that file like so.

<?php
$file = 'Place the destination of your file here!';
$data = fetch_file_data($file);
echo $data['Name'];
echo $data['Email'];
echo $data['URL'];
?>

For the email and web url you can display them as actual links.

echo '<a href="mailto:'.$data['Email'].'">'.$data['Email'].'</a>';
echo '<a href="'.$data['URL'].'">'.$data['URL'].'</a>';

How do I write my hidden data at the top of the file?

<?php
/*
Name: John Smith
Email: [email protected]
URI: http://www.example.com
*/
?>

Continue Reading

Tags: ,

21 March 2011 ~ Comments Off

Adding shortcut links in your website for IE9

Microsoft is almost ready to release the final version IE9 which means that the new browser will soon be complete. One great feature that has been added to integrate with Windows 7 users is short cut / action links. These are only shown in the task list when you right click on the pinned application on your task bar.

A maximum of 5 links can be added with there own icon to represent the page of that link.

To add these links they must be added in the header of your source code were the rest of your meta tags are held. Simply copy the code below and adjust to your own.

<meta name="msapplication-task" content="name=Homepage; action-uri=http://www.yourdomainname.com; icon-uri=http://www.yourdomainname.com/favicon.ico" />

This will be one of the features I will be adding to the Oceans Themes framework.

Continue Reading

Tags:

21 February 2011 ~ Comments Off

Translating Strings

Translating your website can be the most time consuming thing to do if you are supporting other languages for a more global audience and to do that, you require a system that you can easily keep building and translate your strings later without having to go back and replace all the strings that requires a function to load the language the visitor wishes to read your website in.

WordPress is one example of a system that allows developers to provide either there themes or plug-ins in several languages by simply translating a file that stores all the strings side by side (original / translation) of each other. If a string is not translated it will load the original string.

I have created a similar function that you can use for your site if it is coded in PHP.

Simply copy and paste this function in the file you wish to store it.

function text($pages,$string){
        global $page;

        if($page[$pages][$string] == ''){
                $loadString = $string;
        }
        else{
                $loadString = $page[$pages][$string];
        }
        echo $loadString;
}

To use it, simply write:

<?php text('pagename', 'Your text string goes here.'); ?>

Now you are wondering what do I change ‘pagename’ too. That’s easy, if the string is on the homepage only then you would put ‘homepage’ in place of ‘pagename’. If the string is something that is shared or loaded on every page like your menu navigation then you would put ‘mainnavigation’ in place instead.

How do I translate my strings?

First you need a new file created and saved as the default strings you are going to produce translations of i.e. ‘default.php‘ .

Now you write your strings like so:

<?php
$page['homepage']['Welcome to my website.'] = 'Welcome to my website.';
?>

Copy the default strings file and save it as another language i.e. ‘japanese.php‘ . Now you can translate the strings in the new language like so:

<?php
$page['homepage']['Welcome to my website.'] = '私のウェブサイトへようこそ.';
?>

And that’s it. How you decide to load your language files on your site is up to you.

Good luck.

If you liked this post, why don’t you share it with others using Twitter, Facebook, Digg or Stumbleupon on the right hand side or subscribe below to receive new posts in your email.

Continue Reading

Tags: ,

30 January 2011 ~ 1 Comment

WordPress Online Installer Video Tutorial

I said yesterday that I would do a screen recording showing you how the WordPress Online Installer works. Well here it is. This was done off line but does the same online. It will also show you at the end of the video the tables created in the database once WordPress is installed.

Continue Reading

04 December 2010 ~ 4 Comments

Write a WordPress Widget

We are now currently been given one of the best Open Source CMS’s out on the web and we are now on (should be all on) WordPress v3.

Writing a widget for WordPress has changed many times over. How to write the functionality of the widget, what code is no longer accepted and what needs to be changed and because of that you are constantly having to update your widgets for the next new major version release of WordPress. We hope that WordPress won’t be changing to much in the future but just evolve.

WordPress has opened many doors for many ways of using it and one of the great features of WordPress is the widget section. They can be created simply as a Plugin for any user to add to any theme or you can attach it to your theme functions.php file to be built in specifically for that theme.

I have not been able to find any tutorial easily for writing widgets to the full extent of there ability and when I did, I thought it would be best to explain again my self how to write a widget in this tutorial.
[...]

Continue Reading

30 November 2010 ~ 1 Comment

XML Parsing using PHP

I had wanted to write this tutorial sometime ago but never got time to finish it. Now I have. This is a tutorial I hope will help others who have had similar problems parsing XML data using php. [...]

Continue Reading

Tags: ,

16 November 2010 ~ 4 Comments

Integrating bbPress with WordPress the easy way

Time and time again I find my self needing to add a forum for my clients who use WordPress for there site. To make life easy for them i like to integrate bbPress which is written by WordPress and allows you to join the two together as a single system, but you sometimes find your self unable to achieve it easy.

After my experience having trouble understanding how to integrate bbPress with WordPress after and not before I decided to write a tutorial with screenshots step by step showing you how easy it is to integrate bbPress with WordPress at the very beginning.

Please note that in the near future this tutorial might be invalid as bbPress will be a plugin feature to WordPress instead so there will be no need to integrate.

In the mean time this is how we do it. Are you ready? [...]

Continue Reading

Tags:

22 November 2009 ~ Comments Off

Detecting IE with PHP

I needed something to help me detect just IE6 so that I can have the site load things that only work on IE6 and not everything. So I came across this and thought I share it with those who also need it. It also detects IE that don’t exist yet.

function iever($compare=false, $to=NULL){
 if(!preg_match('#MSIE (\d)#', $_SERVER['HTTP_USER_AGENT'], $m)
 || preg_match('#Opera#', $_SERVER['HTTP_USER_AGENT']))
 return false === $compare ? false : NULL;

 if(false !== $compare
 &amp;&amp; in_array($compare, array('&lt;', '&gt;', '&lt;=', '&gt;=', '==', '!='))
 &amp;&amp; in_array((int)$to, array(5,6,7,8,9,10))){
 // if IE isn't either a) long gone
 // or b) fixed permanently from needing this function by version 10 I am retiring
 return eval('return ('.$m[1].$compare.$to.');');
 }
 else{
 return (int)$m[1];
 }
}

With that function, you can do the things like:

if(iever()) // this is a version of IE
if(iever('&lt;', 8)) // is IE less than 8
if(iever('&gt;=', 7)) // is IE greater or equal than 7
if(iever('!=', 6)) // isn't IE6

and more. I will leave the rest for you to figure out.

Original source: http://shru.us/160

Continue Reading

Tags: ,

31 October 2009 ~ Comments Off

Cleaning Windows 7 Temp files and Temporary Internet files

First of all locating the new Temporary folder location took some time but now that I have done it I am able to update you on a previous post that I did for cleaning a users temp files and temporary internet files.

Now you can create a new batch file to do just the same for the new Windows 7.

note: I take no responsabilties on what happenes to your computer if you use this and something goes wrong.

[...]

Continue Reading

One of 347 websites proudly supporting Earth Hour.    Use WordPress? Get the plugin.
Performance Optimization WordPress Plugins by W3 EDGE