Thursday, 29 January 2015

Theme Integration in wordpress

Source : http://codex.wordpress.org/Integrating_WordPress_with_Your_Website



Introduction

By nature, WordPress is very powerful. It can be as complex or as simple as you wish. With that in mind, how much you want to use WordPress with your existing website is totally up to you. There may be only a few features of WordPress you want to use when integrating it with your site, or you may want your entire site run with WordPress. This tutorial will guide you through making your WordPress site look like your current design. We will start with how to make a WordPress blog look like the rest of your site. Then we can move on to making your entire site running on WordPress.
These directions will not work on a MultiSite Network.

Begin the transformation

First, assume you have an existing site at http://myexample.com. Next, create a new sub-directory (folder) at your site and call it 'blog' (you could use something other than blog, but you must create this sub-directory). So you now have an empty sub-directory at http://myexample.com/blog/. Now, download WordPress and upload all of its files into this new folder, and install WordPress.

Grab the header

In order to transform regular PHP pages into ones that utilize WordPress, you need to add either of the following code snippets to the start of each page.
<?php 
/* Short and sweet */
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
?>
<?php
require('/the/path/to/your/wp-blog-header.php');
?>

The Loop

It is necessary to include The Loop in your pages to effectively take advantage of the multitude of Template Tags or plugins available. Familiarize yourself with The Loop and the basics of The Loop in Action to get underway with integrating the power of WordPress into your website.

Examples

Generate a list

In the event you want to show ten posts sorted alphabetically in ascending order on your web page, you could do the following to grab the posted date, title and excerpt:
<?php
require('/the/path/to/your/wp-blog-header.php');
?>

<?php
$posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) : setup_postdata( $post ); ?>
<?php the_date(); echo "<br />"; ?>
<?php the_title(); ?>    
<?php the_excerpt(); ?> 
<?php
endforeach;
?>

Last three posts

Display the last three posts on your web page.
// Get the last 3 posts.

<?php
global $post;
$args = array( 'posts_per_page' => 3 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a><br />
<?php endforeach; ?>

Making a theme

The first portion of this tutorial described how to take components of WordPress and integrate them into your existing site. You may wish to stop right now, but perhaps you would like to create a WordPress theme that would eventually replace web pages on your site.
You will need to create a custom theme. A theme is a set of files used to tell WordPress how to display the site and Using_Themes is fundamental to WordPress. Go to your themes folder (located at /wp-content/themes/), create a new folder and call it "mytheme". This is where you will be adding files to control your site's look. You may wish to acquaint yourself with Theme_Development at this time. The basic theme files are index.php, style.css, single.php, and comments.php.
A little known, but very helpful HTML element, <base> is going to help you out a lot. It instructs the browser to use a specified URL for relative paths:
 <base href="http://myexample.com" />
Normally, the <base> would be your current URL. For example, the default <base> at your blog will be http://myexample.com/blog/. By changing it with the <base> element, you tell the browser to look for files at http://myexample.com/. Why is this useful? When copying and pasting HTML from your current site, you will have references to something like:
 <img src="me.jpg" alt="" />
When you copy this HTML to your theme, the browser will be looking for http://myexample.com/blogs/me.jpg, when the file actually exists at http://myexample.com/me.jpg. Using <base href="http://myexample.com" />, the browser is told the right place to find the files and you do not have to edit every reference to every file that you copied from your main site.

Installing WordPress

Source : http://codex.wordpress.org/Installing_WordPress


WordPress is well-known for its ease of installation. Under most circumstances, installing WordPress is a very simple process and takes less than five minutes to complete. Many web hosts now offer tools (e.g. Fantastico) to automatically install WordPress for you. However, if you wish to install WordPress yourself, the following guide will help. Now with Automatic Upgrade, upgrading is even easier.
The following installation guide will help you, whether you go for the Famous 5 Minute Installation, or require the more detailed installation guide.

Things to Know Before Installing WordPress

Before you begin the install, there are a few things you need to have and do.
These are:

Things You Need to Do to Install WordPress

Begin your installation by:
  1. Checking to ensure that you and your web host have the minimum requirements to run WordPress.
  2. Download the latest release of WordPress.
  3. Unzip the downloaded file to a folder on your hard drive.
  4. Be prepared with a secure password for your Secret Key
  5. Print this page out so you have it handy during the installation.

Famous 5-Minute Install

Here's the quick version of the instructions for those who are already comfortable with performing such installations. More detailed instructions follow.
If you are not comfortable with renaming files, step 3 is optional and you can skip it as the install program will create the wp-config.php file for you.
  1. Download and unzip the WordPress package if you haven't already.
  2. Create a database for WordPress on your web server, as well as a MySQL user who has all privileges for accessing and modifying it.
  3. (Optional) Find and rename wp-config-sample.php to wp-config.php, then edit the file (see Editing wp-config.php) and add your database information.
  4. Upload the WordPress files to the desired location on your web server:
    • If you want to integrate WordPress into the root of your domain (e.g. http://example.com/), move or upload all contents of the unzipped WordPress directory (excluding the WordPress directory itself) into the root directory of your web server.
    • If you want to have your WordPress installation in its own subdirectory on your website (e.g. http://example.com/blog/), create the blog directory on your server and upload the contents of the unzipped WordPress package to the directory via FTP.
    • Note: If your FTP client has an option to convert file names to lower case, make sure it's disabled.
  5. Run the WordPress installation script by accessing the URL in a web browser. This should be the URL where you uploaded the WordPress files.
    • If you installed WordPress in the root directory, you should visit: http://example.com/
    • If you installed WordPress in its own subdirectory called blog, for example, you should visit: http://example.com/blog/
That's it! WordPress should now be installed.

Detailed Instructions

Step 1: Download and Extract

If you work on your own computer, on most Linux distributions you can install WordPress automatically: on Mageia (KDE), thanks to Mageia control center; on Fedora 20 (Gnome), you will not find it in "Software", which only include applications with proper GUI, but you can install from there a package called "Packages" containing the application "Packages", alias "Software install", and, thanks to "Packages", you can install WordPress. We advise you to install PhpMyAdmin at the same time.
Download and unzip the WordPress package from http://wordpress.org/download/.
  • If you will be uploading WordPress to a remote web server, download the WordPress package to your computer with a web browser and unzip the package.
  • If you will be using FTP, skip to the next step - uploading files is covered later.
  • If you have shell access to your web server, and are comfortable using console-based tools, you may wish to download WordPress directly to your web server using wget (or lynx or another console-based web browser) if you want to avoid FTPing:
    • wget http://wordpress.org/latest.tar.gz
    • Then unzip the package using:
      tar -xzvf latest.tar.gz

      The WordPress package will extract into a folder called wordpress in the same directory that you downloaded latest.tar.gz.

Step 2: Create the Database and a User

If you are using a hosting provider, you may already have a WordPress database set up for you, or there may be an automated setup solution to do so. Check your hosting provider's support pages or your control panel for clues about whether or not you'll need to create one manually.
If you determine that you'll need to create one manually, follow the instructions for accessing phpMyAdmin on various servers, or follow the instructions for Using Plesk, Using cPanel or Using phpMyAdmin below.
If you are installing WordPress on your own web server, follow the Using phpMyAdmin or Using the MySQL Client instructions below to create your WordPress username and database.
If you have only one database and it is already in use, you can install WordPress in it - just make sure to have a distinctive prefix for your tables to avoid over-writing any existing database table.

Using Plesk

If your hosting provider supplies the Plesk hosting control panel and you want to install WordPress manually, follow the instructions below to create a database:
  1. Log in to Plesk.
  2. Click Databases in the Custom Website area of your website on the Websites & Domains page:Database management on a website
  3. Click Add New Database, change database name if you want, create database user by providing credentials and click OK. You're done!

Using cPanel

If your hosting provider supplies the cPanel hosting control panel, you may follow these simple instructions to create your WordPress username and database. A more complete set of instructions for using cPanel to create the database and user can be found in Using cPanel.
  1. Log in to your cPanel.
  2. Click MySQL Database Wizard icon under the Databases section.
  3. In Step 1. Create a Database enter the database name and click Next Step.
  4. In Step 2. Create Database Users enter the database user name and the password. Make sure to use a strong password. Click Create User.
  5. In Step 3. Add User to Database click the All Privileges checkbox and click Next Step.
  6. In Step 4. Complete the task note the database name and user. Write down the values of hostname, username, databasename, and the password you chose. (Note that hostname will usually be localhost.)

Using Lunarpages.com's custom cPanel (LPCP)

Lunarpages has developed their own version of cPanel.
  1. Log in to your account.
  2. Go to Control Panel.
  3. Click on the button on the left panel labeled 'Go to LPCP'.
  4. Go to MySQL Manager.
  5. Add the user name and database name but leave the host name as the default IP number.
  6. Note the IP address of the database on the right which is different from the default IP number of the host indicated in the above step.
  7. When modifying the WP-CONFIG.PHP file, use the DB IP number, not 'LOCALHOST'.
  8. When modifying the WP-CONFIG.PHP file, be sure to use the full name of the database and user name, typically 'accountname_nameyoucreated'.
  9. Refer to http://wiki.lunarpages.com/Create_and_Delete_MySQL_Users_in_LPCP for more info.

Using phpMyAdmin

If your web server has phpMyAdmin installed, you may follow these instructions to create your WordPress username and database. If you work on your own computer, on most Linux distributions you can install PhpMyAdmin automatically.
Note: These instructions are written for phpMyAdmin 3.5; the phpMyAdmin user interface can vary slightly between versions.
  1. If a database relating to WordPress does not already exist in the Database dropdown on the left, create one:
    1. Choose a name for your WordPress database: 'wordpress' or 'blog' are good, but most hosting services (specially shared hosting) will require a name beginning with your username there and an underscore, so, even if you work on your own computer, we advise you to check now your hosting service requirements so that you conform with them on your own server and would be able to transfer your database without modification when it will be ready. Enter the chosen database name in the Create database field and choose the best collation for your language and encoding. In most cases it's better to choose in the "utf8_" series and, if you don't find your language, to choose "utf8_unicode_ci" (Reference: StackOverFlow.com).
      After naming the database (here "fiable_wordpress") and choosing the collation (here "unicode_general_ci"), click on the Create button
  2. Click the phpMyAdmin icon in the upper left to return to the main page, then click the Users tab. If a user relating to WordPress does not already exist in the list of users, create one:
    users.jpg
    1. Click Add user.
    2. Choose a username for WordPress ('wordpress' is good) and enter it in the User name field. (Be sure Use text field: is selected from the dropdown.)
    3. Choose a difficult-to-guess password (ideally containing a combination of upper- and lower-case letters, numbers, and symbols), and enter it in the Password field. (Be sure Use text field: is selected from the dropdown.) Re-enter the password in the Re-type field.
    4. Write down the username and password you chose.
    5. Leave all options under Global privileges at their defaults.
    6. Click Go.
  3. Return to the Users screen and click the Edit privileges icon on the user you've just created for WordPress. In the Database-specific privileges section, select the database you've just created for WordPress under the Add privileges to the following database dropdown. The page will refresh with privileges for that database. Click Check All to select all privileges, and click Go.
  4. On the resulting page, make note of the host name listed after Server: at the top of the page. (This will usually be localhost.)

Using the MySQL Client

You can create MySQL users and databases quickly and easily by running mysql from the shell. The syntax is shown below and the dollar sign is the command prompt:
$ mysql -u adminusername -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5340 to server version: 3.23.54
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
mysql> CREATE DATABASE databasename;
Query OK, 1 row affected (0.00 sec)
 
mysql> GRANT ALL PRIVILEGES ON databasename.* TO "wordpressusername"@"hostname"
    -> IDENTIFIED BY "password";
Query OK, 0 rows affected (0.00 sec)
  
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> EXIT
Bye
$ 
The example shows:
  • that root is also the adminusername. It is a safer practice to choose a so-called "mortal" account as your mysql admin, so that you are not entering the command "mysql" as the root user on your system. (Any time you can avoid doing work as root you decrease your chance of being exploited). The name you use depends on the name you assigned as the database administrator using mysqladmin.
  • wordpress or blog are good values for databasename.
  • wordpress is a good value for wordpressusername but you should realize that, since it is used here, the entire world will know it too.
  • hostname will usually be localhost. If you don't know what this value should be, check with your system administrator if you are not the admin for your Wordpress host. If you are the system admin, consider using a non-root account to administer your database.
  • password should be a difficult-to-guess password, ideally containing a combination of upper- and lower-case letters, numbers, and symbols. One good way of avoiding the use of a word found in a dictionary is to use the first letter of each word in a phrase that you find easy to remember.
If you need to write these values somewhere, avoid writing them in the system that contains the things protected by them. You need to remember the value used for databasename, wordpressusername, hostname, and password. Of course, since they are already in (or will be shortly) your wp-config.php file, there is no need to put them somewhere else, too.


Using DirectAdmin

a. Regular "User" of a single-site webhosting account logs in normally. Then click "MySQL Management." (If this is not readily visible, perhaps your host needs to modify your "package" to activate MySQL.) Then follow part "c" below.
b. "Reseller" accounts or "Admin" accounts may need to click "User Level." They also must first log-in as "Reseller" if the relevant domain is a Reseller's primary domain... or log-in as a "User" if the domain is not a Reseller's primary domain. If a Reseller's primary domain, then when logged-in as Reseller, you simply click "User Level." However if the relevant domain is not the Reseller's primary domain, then you must log-in as the relevant User. Then click "MySQL Management." (If not readily visible, perhaps you need to return to the Reseller or Admin level, and modify the "Manage user package" or "Manage Reseller package" to enable MySQL.)
c. In "MySQL Management," click on the small words: "Create new database." Here you are asked to submit two suffixes for the database and its username. For maximum security, use two different sets of 4-6 random characters. Then the password field has a "Random" button that generates an 8-character password. You may also add more characters to the password for maximum security. "Create." The next screen will summarize the database, username, password and hostname. Be sure to copy and paste these into a text file for future reference.

Step 3: Set up wp-config.php

You can either create and edit the wp-config.php file yourself, or you can skip this step and let WordPress try to do this itself when you run the installation script (step 5) (you'll still need to tell WordPress your database information).
(For more extensive details, and step by step instructions for creating the configuration file and your secret key for password security, please see Editing wp-config.php.)
Return to where you extracted the WordPress package in Step 1, rename the file wp-config-sample.php to wp-config.php, and open it in a text editor.
Enter your database information under the section labeled
 // ** MySQL settings - You can get this info from your web host ** //
DB_NAME 
The name of the database you created for WordPress in Step 2 .
DB_USER 
The username you created for WordPress in Step 2.
DB_PASSWORD 
The password you chose for the WordPress username in Step 2.
DB_HOST 
The hostname you determined in Step 2 (usually localhost, but not always; see some possible DB_HOST values). If a port, socket, or pipe is necessary, append a colon (:) and then the relevant information to the hostname.
DB_CHARSET 
The database character set, normally should not be changed (see Editing wp-config.php).
DB_COLLATE 
The database collation should normally be left blank (see Editing wp-config.php).
Enter your secret key values under the section labeled
  * Authentication Unique Keys.
Save the wp-config.php file.
For information on enabling SSL in WordPress 2.6, see SSL and Cookies in WordPress 2.6.

Step 4: Upload the files

Now you will need to decide where on your domain you'd like your WordPress-powered site to appear:
  • In the root directory of your website. (For example, http://example.com/)
  • In a subdirectory of your website. (For example, http://example.com/blog/)
Note: The location of your root web directory in the filesystem on your web server will vary across hosting providers and operating systems. Check with your hosting provider or system administrator if you do not know where this is.

In the Root Directory

  • If you need to upload your files to your web server, use an FTP client to upload all the contents of the wordpress directory (but not the directory itself) into the root directory of your website.
  • If your files are already on your web server, and you are using shell access to install WordPress, move all of the contents of the wordpress directory (but not the directory itself) into the root directory of your website.

In a Subdirectory

  • If you need to upload your files to your web server, rename the wordpress directory to your desired name, then use an FTP client to upload the directory to your desired location within the root directory of your website.
  • If your files are already on your web server, and you are using shell access to install WordPress, move the wordpress directory to your desired location within the root directory of your website, and rename the directory to your desired name.
Note: If your FTP client has an option to convert file names to lower case, make sure it's disabled.

Step 5: Run the Install Script

Point a web browser to start the installation script.
  • If you placed the WordPress files in the root directory, you should visit: http://example.com/wp-admin/install.php
  • If you placed the WordPress files in a subdirectory called blog, for example, you should visit: http://example.com/blog/wp-admin/install.php

Setup configuration file

If WordPress can't find the wp-config.php file, it will tell you and offer to try to create and edit the file itself. (You can do also do this directly by loading wp-admin/setup-config.php in your web browser.) WordPress will ask you the database details and write them to a new wp-config.php file. If this works, you can go ahead with the installation; otherwise, go back and create, edit, and upload the wp-config.php file yourself (step 3).
Enter database information

Finishing installation

The following screenshots show how the installation progresses. Notice in Entering the details screen, you enter your site title, your desired user name, your choice of a password (twice) and your e-mail address. Also displayed is a check-box asking if you would like your blog to appear in search engines like Google and Technorati. Leave the box checked if you would like your blog to be visible to everyone, including search engines, and uncheck the box if you want to block search engines, but allow normal visitors. Note all this information can be changed later in your Administration Panels.
Version 3.0
Enter site, login, and email
All done!

Install Script Troubleshooting

  • If you get an error about the database when you run the install script:
    • Go back to Step 2 and Step 3, and be sure you got all the correct database information and that it was entered correctly into wp-config.php.
    • Be sure you granted your WordPress user permission to access your WordPress database in Step 3.
    • Be sure the database server is running.

Common Installation Problems

The following are some of the most common installation problems. For more information and troubleshooting for problems with your WordPress installation, check out FAQ Installation and FAQ Troubleshooting.
I see a directory listing rather than a web page.
The web server needs to be told to view index.php by default. In Apache, use the DirectoryIndex index.php directive. The simplest option is to create a file named .htaccess in the installed directory and place the directive there. Another option is to add the directive to the web server's configuration files.
I see lots of Headers already sent errors. How do I fix this?
You probably introduced a syntax error in editing wp-config.php.
  1. Download wp-config.php (if you don't have shell access).
  2. Open it in a text editor.
  3. Check that the first line contains nothing but <?php, and that there is no text before it (not even whitespace).
  4. Check that the last line contains nothing but ?>, and that there is no text after it (not even whitespace).
  5. If your text editor saves as Unicode, make sure it adds no byte order mark (BOM). Most Unicode-enabled text editors do not inform the user whether it adds a BOM to files; if so, try using a different text editor.
  6. Save the file, upload it again if necessary, and reload the page in your browser.
My page comes out gibberish. When I look at the source I see a lot of "<?php ?>" tags.
If the <?php ?> tags are being sent to the browser, it means your PHP is not working properly. All PHP code is supposed to be executed before the server sends the resulting HTML to your web browser. (That's why it's called a preprocessor.) Make sure your web server meets the requirements to run WordPress, that PHP is installed and configured properly, or contact your hosting provider or system administrator for assistance.
I keep getting an Error connecting to database message but I'm sure my configuration is correct.
Try resetting your MySQL password manually. If you have access to MySQL via shell, try issuing:
SET PASSWORD FOR 'wordpressusername'@'hostname' = OLD_PASSWORD('password');
If you are using a version of MySQL prior to 4.1, use PASSWORD instead of OLD_PASSWORD. If you do not have shell access, you should be able to simply enter the above into an SQL query in phpMyAdmin. Failing that, you may need to use your host's control panel to reset the password for your database user.
My image/MP3 uploads aren't working.
If you use the Rich Text Editor on a blog that's installed in a subdirectory, and drag a newly uploaded image into the editor field, the image may vanish a couple seconds later. This is due to a problem with TinyMCE (the rich text editor) not getting enough information during the drag operation to construct the path to the image or other file correctly. The solution is to NOT drag uploaded images into the editor. Instead, click and hold on the image and select "Send to Editor."

Automated Installation

Although WordPress is very easy to install, you can use one of the one-click autoinstallers typically available from hosting companies. Most popular autoinstallers, APS, Fantastico, Installatron, and Softaculous are described here.

APS (Plesk)

If you're using the Plesk control panel, you have two options: one-click quick install or custom install which allows you to configure things like installation path or database prefix. Both these options are available regardless of whether you have WordPress Toolkit enabled or not. However, special security measures are applied during installation only if WordPress Toolkit is enabled. If you don't have WordPress Toolkit, your WordPress installations will have the same security as manual WordPress installs.
  1. Log in to your Plesk account and go to Applications tab. The Featured Applications screen will open.
  2. Click Install next to WordPress if you want a one-click quick install, or click the drop-down arrow next to Install and click Custom if you want to change installation parameters.
  3. If you chose quick installation, no need to do anything else, as your WordPress blog has already been installed. If you chose custom installation, change the settings you want and click Install.
plesk-aps-1.png

Fantastico

  1. Login to your cPanel account and click on the Fantastico (or Fantastico Deluxe) option
  2. Once you enter Fantastico on the left hand side there is a 'Blogs' Category under which WordPress is there. Click on it.
  3. Click on the 'New Installation' Link in the WordPress Overview
  4. Fill in the various details and Submit.
  5. That's it you are done!
fant.jpg

Installatron

Installatron is a one-click web application installer that enables WordPress and other top web applications to be instantly installed and effortlessly managed. WordPress installations managed by Installatron can updated (manually or automated), cloned, backed up and restored, edited to change installation parameters, and more.
Many web hosting providers include Installatron through their web hosting control panel. If Installatron is not available from your provider, you can use Installatron directly from Installatron.com.
To install WordPress through your web hosting provider's control panel:
  1. Login to your web host's control panel, navigate to "Installatron", click "WordPress", and choose the "Install this application" option.
  2. Change any of the install prompts to customize the install. For example, you can choose a different language for WordPress.
  3. Click the "Install" button to begin the installation process. You will be redirect to a progress page where you can watch as WordPress is installed within a few seconds to your website.
To install WordPress using Installatron.com:
  1. Navigate to WordPress and choose the "Install this application" option.
  2. Enter your hosting account's FTP or SSH account information, and then enter MySQL database information for a created database. For increased security, create a separate FTP account and MySQL database for your WordPress installation.
  3. Change any of the install prompts to customize the install. For example, you can choose a different language for WordPress.
  4. Click the "Install" button to begin the installation process. You will be redirect to a progress page where you can watch as WordPress is installed within a few seconds to your website.

Softaculous

  1. Login to your host and look for Software/Services
  2. In Softaculous there is a 'Blogs' Category. Collapse the category and WordPress will be there. Click on it.
  3. You will see an 'Install' TAB. Click it.
  4. Fill in the various details and Submit.
  5. That's it, you are done!
soft.jpg

Installation Instructions in Other Languages

For installation instructions in other languages, see WordPress in Your Language.

Installing Multiple Blogs

Detailed information about Installing Multiple Blogs is available.

Installing WordPress on your own Computer

Local Installation Instructions

Use these instruction for setting up a local server environment for testing and development.
Installing WordPress locally is usually meant for the purpose of development. Those interested in development should follow the instructions below and download WordPress locally.

Software Appliance - Ready-to-Use

You may find that using a pre-integrated software appliance is a great way to get up and running with WordPress, especially in combination with virtual machine software (e.g., VMWare, VirtualBox, Xen HVM, KVM).
Another software that can be used is parallels which you would have to pay for unlike virtual machine software. Which allows you to run both Mac and Windows on your machine.
A software appliance allows users to altogether skip manual installation of WordPress and its dependencies, and instead deploy a self-contained system that requires little to no setup, in just a couple of minutes.
  • TurnKey WordPress Appliance: a free Debian-based appliance that just works. It bundles a collection of popular WordPress plugins and features a small footprint, automatic security updates, SSL support and a Web administration interface. Available as ISO, various virtual machine images, or launch in the cloud.
  • BitNami WordPress Appliance: free WordPress appliances based on Ubuntu or Open Suse. Native installer and Cloud images also available. There are also virtual machines for WordPress Multisite already configured.
  • UShareSoft WordPress Appliance: free WordPress appliance for many of the major virtualization and cloud platforms (Cloud.com, Xen, VMware, OVF, Abiquo)

Easy 5 Minute WordPress Installation on Windows

Download, install, and configure WordPress with the Microsoft Web Platform Installer (Web PI). Installation is very easy and takes on average about 5 minutes to complete. For other Windows installers, check this section
Step 1. Things you need to know before starting.
  1. These steps will work on Windows versions which include IIS, such as Windows XP professional, Windows Vista, Windows 7, Windows 8 and Windows Server.
  2. You must be able to install programs on your machine (i.e. have administrator rights).
  3. Once Web PI is installed, neither XAMPP nor any other web server will be able to use localhost to host a website locally on your machine.
Step 2. Navigate to the WordPress Installation Page
  1. Choose the "Install" button.
  2. If you have Web PI already installed, it will automatically be launched and you can skip to the next step.
  3. If you do not have the Web Platform Installer, you will be prompted to install it.
  4. Web PI is a tool from Microsoft that downloads and installs the latest components you need to develop or host Web applications on Windows. Everything in the tool is free. Web PI will install and configure IIS, PHP, MySQL and anything else you may need.
Step 3. Choose to Install WordPress
  1. When Web PI launches, you will see an information page for WordPress. Start installing WordPress by pressing the "Install" button in the lower right hand corner.
Step 4. Installation of WordPress and its requirements
  1. Finding Dependencies: Web PI will determine the minimum set of components and modules you need on your machine to run WordPress. It will only install what you’re missing. For example, PHP will be installed and configured to run WordPress.
  2. Configure the Database: After accepting the terms, if you need to install MySQL, you will be asked to create a password for the root account database account. Keep this password safe. WordPress will ask for this information later.
  3. Choose the site: Choose a site to install WordPress to. You may install to an existing website in IIS or create a new site. Use the default setting if you do not have advanced configuration needs.
  4. WordPress Setup: WordPress will need answers to a few specific questions such as the username (in the case of a new MySQL install is root) and password for your MySQL database to complete the install.
Step 5. Completion
  1. Once you enter the WordPress setup information, Web PI will finish the installation.
  2. Click, Launch in Browser and WordPress will launch.
Alternatively, the BitNami WordPress installer is a free, self-contained native installer for WordPress that includes Apache, MySQL and PHP so it works out of the box.

WAMP

If you don't have IIS on your computer or don't want to use it, you could use a WAMP Stack :
These stacks can be downloaded freely and set up all the bits you need on your computer to run a website. Once you have downloaded and installed WAMP, you can point your browser at localhost and use the link to phpmyadmin to create a database.
Then, in order to install WordPress, download the zip file, and extract it into the web directory for your WAMP installation (this is normally installed as c:\wamp\www). Finally visit http://localhost/wordpress to start the WordPress install. (Assuming you extracted into c:\wamp\www\wordpress).
Tip: If you want to use anything other than the default permalink structure on your install, make sure you enable the mod_rewrite module in WAMP. This can be enabled by clicking on the WAMP icon in the taskbar, then hover over Apache in the menu, then Apache modules and ensure that the rewrite_module item has a checkmark next to it.

Installing WordPress at popular Hosting Companies

Installing WordPress at AWS

Installing WordPress at DigitalOcean

  • How to Install WordPress at Digital Ocean on Ubuntu 14.04 LTS: A step by step guide to installing and configuring a Droplet with WordPress suitable for optimization with Varnish and W3 Total Cache. Because Digital Ocean uses Solid State Drives (SSD), performance with even the least expensive droplet can be quite good.

Installing through wp-cli

wp-cli is a great command line tool with which you can easily install and update WordPress and themes and extensions.

Moving an Existing WordPress Blog

How to Themes use in Wordpress

Source : http://codex.wordpress.org/Using_Themes


What is a Theme?

Fundamentally, the WordPress Theme system is a way to "skin" your weblog. Yet, it is more than just a "skin." Skinning your site implies that only the design is changed. WordPress Themes can provide much more control over the look and presentation of the material on your website.
A WordPress Theme is a collection of files that work together to produce a graphical interface with an underlying unifying design for a weblog. These files are called template files. A Theme modifies the way the site is displayed, without modifying the underlying software. Themes may include customized template files, image files (*.jpg, *.gif), style sheets (*.css), custom Pages, as well as any necessary code files (*.php). For an introduction to template files, see Stepping Into Templates.
Let's say you write a lot about cheese and gadgets. Through the use of the WordPress Loop and template files, you can customize your Cheese category posts to look different from your Gadgets category posts. With this powerful control over what different pages and categories look like on your site, you are limited only by your imagination. For information on how to use different Themes for different categories or posts, see The Loop in Action and Category Templates.

Get New Themes

The WordPress Theme Directory is the official site for WordPress Themes which have been checked and inspected, and are free for downloading. The site features the ability to search by type and style, and offers a demonstration of the page view elements of the Theme.

Using Themes

WordPress currently comes with four themes: the default Twenty Fifteen theme, and previous defaults Twenty Fourteen theme, Twenty Thirteen theme and Twenty Twelve theme. You can switch between Themes using the Appearance admin panel. Themes that you add to the theme directory will appear in the Administration Screen > Appearance > Themes as additional selections.

Adding New Themes

Appearance Panel
There are many Themes available for download that will work with your WordPress installation.
If the Theme that you are installing provides instructions, be sure to read through and follow those instructions for the successful installation of the Theme. It is recommended that Theme developers provide installation instructions for their own Themes, because Themes can provide special optional functionality that may require more steps than the basic installation steps covered here. If your Theme does not work after following any provided instructions, please contact the Theme author for help.

Adding New Themes using the Administration Panels

You can download Themes directly to your blog by using the Add New Themes option in the Appearance sub-menu.
  1. Log in to the WordPress Administration Panels.
  2. Select the Appearance panel, then Themes.
  3. Select Add New.
  4. Either use the Search or Filter options to locate a Theme you would like to use.
  5. Click on the Preview link to preview the Theme or the Install Now link to upload the Theme to your blog,
  6. Or use the Upload link in the top links row to upload a zipped copy of a Theme that you have previously downloaded to your machine.

Adding New Themes by using cPanel

If your host offers the cPanel control panel, and the Theme files are in a .zip or .gz archive follow these instructions. Note: This assumes the Theme you download is a compressed (.zip) file containing a folder under which all the Theme files reside.
  1. Download the Theme .zip file to your local machine.
  2. In cPanel File Manager, navigate to your Themes folder. If your WordPress is installed in the document root folder of your web server you would navigate to "public_html/wp-content/themes" and if you have WordPress installed in a sub-folder called wordpress, you would navigate to "public_html/wordpress/wp-content/themes".
  3. Once you've navigated to the Themes folder in cPanel File Manager, click on Upload file(s) and upload that .zip file you saved in Step 1.
  4. Once the .zip file is uploaded, click on the name of that file in cPanel, then in the panel to the right, click on "Extract File Contents", and that .zip file will be uncompressed.
  5. Follow the instructions below for selecting the new Theme.

Adding New Themes Manually (FTP)

To add a new Theme to your WordPress installation, follow these basic steps:
  1. Download the Theme archive and extract the files it contains. You may need to preserve the directory structure in the archive when extracting these files. Follow the guidelines provided by your Theme author.
  2. Using an FTP client to access your host web server, create a directory to save your Theme in the wp-content/themes directory provided by WordPress. For example, a Theme named Test should be in wp-content/themes/test. Your Theme may provide this directory as part of the archive.
  3. Upload the Theme files to the new directory on your host server.
  4. Follow the instructions below for selecting the new Theme.

Selecting the Active Theme

To select a Theme for your site:
  1. Log in to the WordPress Administration Panels.
  2. Select the Appearance panel, then Themes.
  3. From the Themes panel, roll over the Theme thumbnail image for the Theme you are interested in to see options for that theme.
  4. You can view more information about any theme by clicking Theme Details.
  5. A live preview of any Theme (using your blog's content) can be seen by clicking Live Preview.
  6. To activate the Theme click the Activate button.
Your selection will immediately become active.
Note: If the Theme preview is blank, do not activate the new Theme without investigating further. Your site may not be displayed correctly, otherwise.

Creating Themes

If you are interested in creating your own Theme for distribution, or learning more about the architecture of Themes, please review the documentation regarding Theme Development.
If you simply want to customize your current Theme for your own use, consider creating a Child Theme.

Child Themes in Wordpress

Source : http://codex.wordpress.org/Child_Themes

Why use a Child Theme?

There are a few reasons why you would want to use a child theme:
  • If you modify a theme directly and it is updated, then your modifications may be lost. By using a child theme you will ensure that your modifications are preserved.
  • Using a child theme can speed up development time.
  • Using a child theme is a great way to to learn about WordPress theme development.

How to Create a Child Theme

Child Theme directory structure
A child theme consists of at least one directory (the child theme directory) and two files (style.css and functions.php), which you will need to create:
  • The child theme directory
  • style.css
  • functions.php
The first step in creating a child theme is to create the child theme directory, which will be placed in wp-content/themes. It is recommended (though not required, especially if you're creating a theme for public use) that the name of your child theme directory is appended with '-child'. You will also want to make sure that there are no spaces in your child theme directory name, which may result in errors. In the screenshot above we have called our child theme 'twentyfifteen-child', indicating that the parent theme is the Twenty Fifteen theme.
The next step is to create your child theme's stylesheet (style.css). The stylesheet must begin with the following (the stylesheet header):
/*
 Theme Name:   Twenty Fifteen Child
 Theme URI:    http://example.com/twenty-fifteen-child/
 Description:  Twenty Fifteen Child Theme
 Author:       John Doe
 Author URI:   http://example.com
 Template:     twentyfifteen
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Tags:         light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
 Text Domain:  twenty-fifteen-child
*/
A couple things to note:
  • You will need to replace the example text with the details relevant to your theme.
  • The Template line corresponds to the directory name of the parent theme. The parent theme in our example is the Twenty Fifteen theme, so the Template will be twentyfifteen. You may be working with a different theme, so adjust accordingly.
  • The only required child theme file is style.css, but functions.php is necessary to enqueue styles correctly (below).
The final step is to enqueue the parent and child theme stylesheets. Note that the previous method was to import the parent theme stylesheet using @import: this is no longer best practice. The correct method of enqueuing the parent theme stylesheet is to use wp_enqueue_script() in your child theme's functions.php. You will therefore need to create a functions.php in your child theme directory. The first line of your child theme's functions.php will be an opening PHP tag (<?php), after which you can enqueue your parent and child theme stylesheets. The following example function will only work if your Parent Theme uses only one main style.css to hold all of the css. If your theme has more than one .css file (eg. ie.css, style.css, main.css) then you will have to make sure to maintain all of the Parent Theme dependencies. Setting 'parent-style' as a dependency will ensure that the child theme stylesheet loads after it. See here a more detailed discussion :
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

}
Your child theme is now ready for activation. Log in to your site's administration panel, and go to Administration Panels > Appearance > Themes. You should see your child theme listed and ready for activation. (If your WordPress installation is multi-site enabled, then you may need to switch to your network administration panel to enable the theme (within the Network Admin Themes Screen tab). You can then switch back to your site-specific WordPress administration panel to activate your child theme.)
Note: You may need to re-save your menu (Appearance > Menus, or Appearance > Customize > Menus) and theme options (including background and header images) after activating the child theme.

Template Files

If you want to change more than just the stylesheet, your child theme can override any file in the parent theme: simply include a file of the same name in the child theme directory, and it will override the equivalent file in the parent theme directory when your site loads. For instance, if you want to change the PHP code for the site header, you can include a header.php in your child theme's directory, and that file will be used instead of the parent theme's header.php.
You can also include files in the child theme that are not included in the parent theme. For instance, you might want to create a more specific template than is found in your parent theme, such as a template for a specific page or category archive. See the Template Hierarchy for more information about how WordPress decides what template to use.

Using functions.php

Unlike style.css, the functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.)
In that way, the functions.php of a child theme provides a smart, trouble-free method of modifying the functionality of a parent theme. Say that you want to add a PHP function to your theme. The fastest way would be to open its functions.php file and put the function there. But that’s not smart: The next time your theme is updated, your function will disappear. But there is an alternative way which is the smart way: you can create a child theme, add a functions.php file in it, and add your function to that file. The function will do the exact same job from there too, with the advantage that it will not be affected by future updates of the parent theme. Do not copy the full content of functions.php of the parent theme into functions.php in the child theme.
The structure of functions.php is simple: An opening PHP tag at the top, and below it, your bits of PHP. In it you can put as many or as few functions as you wish. The example below shows an elementary functions.php file that does one simple thing: Adds a favicon link to the head element of HTML pages.
<?php // Opening PHP tag - nothing should be before this, not even whitespace

// Custom Function to Include
function favicon_link() {
    echo '<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />' . "\n";
}
add_action( 'wp_head', 'favicon_link' );
TIP FOR THEME DEVELOPERS. The fact that a child theme’s functions.php is loaded first means that you can make the user functions of your theme pluggable —that is, replaceable by a child theme— by declaring them conditionally. E.g.:
if ( ! function_exists( 'theme_special_nav' ) ) {
    function theme_special_nav() {
        //  Do something.
    }
}
In that way, a child theme can replace a PHP function of the parent by simply declaring it beforehand.

Referencing / Including Files in Your Child Theme

When you need to include files that reside within your child theme's directory structure, you will use get_stylesheet_directory(). Because the parent template's style.css is replaced by your child theme's style.css, and your style.css resides in the root of your child theme's subdirectory, get_stylesheet_directory() points to your child theme's directory (not the parent theme's directory).
Here's an example, using require_once, that shows how you can use get_stylesheet_directory when referencing a file stored within your child theme's directory structure.
require_once( get_stylesheet_directory() . '/my_included_file.php' );

Other Useful Information

Using Post Formats

A child theme inherits post formats as defined by the parent theme. When creating child themes, be aware that using add_theme_support('post-formats') will override the formats defined by the parent theme, not add to it.

RTL support

To support RTL languages, add rtl.css file to your child theme, containing:
/*
Theme Name: Twenty Fourteen Child
Template: twentyfourteen
*/

rtl.css is only loaded by WordPress if is_rtl() returns true.
It's recommended to add the rtl.css file to your child theme even if the parent theme has no rtl.css file.

Internationalization

Child themes, much like other extensions, may be translated into other languages by using gettext functions. For an overview, please see Translating WordPress & I18n for WordPress Developers.
To internationalize a child theme follow these steps:
  • Add a languages directory.
    • Something like my-theme/languages/.
  • Add language files.
    • Your filenames have to be he_IL.po & he_IL.mo (depending on your language), unlike plugin files which are domain-he_IL.xx.
  • Load a textdomain.
    • Use load_child_theme_textdomain() in functions.php during the after_setup_theme action.
    • The text domain defined in load_child_theme_textdomain() should be used to translate all strings in the child theme.
  • Use GetText functions to add i18n support for your strings.

Example: textdomain

<?php
/**
 * Setup My Child Theme's textdomain.
 *
 * Declare textdomain for this child theme.
 * Translations can be filed in the /languages/ directory.
 */
function my_child_theme_setup() {
    load_child_theme_textdomain( 'my-child-theme', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'my_child_theme_setup' );
?>

Example: gettext functions

<?php
_e( 'Code is Poetry', 'my-child-theme' );
?>

To sum up, all strings that use "my-child-theme" textdomain will be translatable. The translation files must reside in "/languages/" directory.

Theme Customization in wordpress

source : http://codex.wordpress.org/Theme_Customization_API

Introduction

The Theme Customization API, added in WordPress 3.4, allows developers to customize and add controls to the "Appearance" → "Customize" admin screen. The Theme Customization screen (i.e. "Theme Customizer") allows site admins to tweak a theme's settings, color scheme or widgets, and see a preview of those changes in real time.
This page documents the Theme Customization API (Application Programming Interface), and how to implement it in your own themes.
This article assumes you have already read Theme Development and Writing a Plugin, which give an overview (and many details) of how to develop custom themes and plugins for WordPress. This article also requires a functional understanding of object-oriented programming. A familiarity with the WordPress Settings API should be very helpful as well.
Note: This information applies to WordPress Version 3.4 and higher.

Developing for the Theme Customizer

If you are a theme developer, you can use this API to add more powerful, interactive theme customization options to your theme.
To add your own options to the theme customizer, you need to use a minimum of 2 hooks:
customize_register
This hook allows you define new Theme Customizer sections, settings, and controls.
wp_head
This hook allows you to output custom-generated CSS so that your changes show up correctly on the live website.
Note: Optionally, the customize_preview_init hook can also be used for enqueuing custom JavaScript on the Theme Customizer screen. JavaScript can be used for making the Theme Customizer more responsive and powerful, but this step is not required.
Important: Do not conditionally load your Customizer code with an `is_admin()` check. If you only add your `customize_register` if `is_admin()`, then any panels, sections, or controls will be unavailable when the Customizer preview loads. As of WordPress 4.1, there are contextual panels, sections, and controls so that they can be displayed only on certain URLs being previewed. If you only register your panels, sections, and controls if `is_admin()` then you'll be effectively saying that these are not contextual to any URL on your site. For more information, see #30387 and #29758.

Part 1: Defining Settings, Controls, Etc.

Any new Theme Customizer settings, sections, or controls must be defined from within a customize_register action. This action automatically loads the $wp_customize object, which is an instance of the WP_Customize_Manager class.
First, define the action like this:
function mytheme_customize_register( $wp_customize ) {
   //All our sections, settings, and controls will be added here
}
add_action( 'customize_register', 'mytheme_customize_register' );
Note that the $wp_customize object is passed automatically to the function, and all customizations you make to the Theme Customization page are performed through methods of the $wp_customize object.
Next, you need to define your settings, then your sections, then your controls (controls need a section and a setting to function).

Adding a New Setting

Settings automatically use WordPress's theme_mod features to get/set settings for your theme.
To add a new setting to your Theme Customizer, you need to call the $wp_customize->add_setting() method. By defining your setting this way, you don't need to do any extra work to create, save, or fetch settings for your theme.
Adding a theme setting (within the 'customize_register' action) might look like this:
$wp_customize->add_setting( 'header_textcolor' , array(
    'default'     => '#000000',
    'transport'   => 'refresh',
) );
Note: The 'transport' argument is optional, and defaults to 'refresh'. If left to default, then the theme customizer's preview window will update by completely reloading itself when this setting is changed. If you would prefer to avoid refreshes and improve responsiveness, you can set this to 'postMessage' instead, then handle any styling updates manually with a bit of JavaScript (see the Configure Live Preview section below).

Adding a New Section

Sections are groups of options. When you define new controls, they must be added to a section. Although you can add controls to existing default sections, we will briefly cover adding a new section.
To add a new section to your Theme Customizer, you need to call the $wp_customize->add_section() method.
Adding a theme section (within the 'customize_register' action) might look like this:
$wp_customize->add_section( 'mytheme_new_section_name' , array(
    'title'      => __( 'Visible Section Name', 'mytheme' ),
    'priority'   => 30,
) );
WordPress does include a few built-in sections. If you want to use any of the existing, built-in ones, you don't need to declare them with add_section(). Instead, refer to them by name. The following sections are built-in:
  • title_tagline - Site Title & Tagline
  • colors - Colors
  • header_image - Header Image
  • background_image - Background Image
  • nav - Navigation
  • static_front_page - Static Front Page

Adding a New Control

A control is an HTML form element that renders on the Theme Customizer page and allows admins to change a setting, and preview those changes in real time. Controls are linked to a single setting, and a single section.
To add a new control to your Theme Customizer, you need to call the $wp_customize->add_control() method.
Adding a control to a theme section (within the 'customize_register' action) might look like this:
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array(
 'label'        => __( 'Header Color', 'mytheme' ),
 'section'    => 'your_section_id',
 'settings'   => 'your_setting_id',
) ) );
Controllers have quite a few options, some of which require passing it another class (such as the WP_Customize_Color_Control() class shown in the above example). For more examples, see the documentation for add_control()

Part 2: Generating Live CSS

Finally, you just need to make sure that you're fetching the settings and outputting any necessary CSS into your header. If you defined your settings within a 'customize_register' action, as described above, then getting your setting values is as simple as outputting css with 'wp_head' action and fetching the values with get_theme_mod()
For example, let's say you have a setting called 'header_color' and it looks like this:
$wp_customize->add_setting( 'header_color' , array(
    'default'     => '#000000',
    'transport'   => 'refresh',
) );
Your code to output the css into the header might look something like this:
function mytheme_customize_css()
{
    ?>
         <style type="text/css">
             h1 { color:<?php echo get_theme_mod('header_color', '#000000'); ?>; }
         </style>
    <?php
}
add_action( 'wp_head', 'mytheme_customize_css');
When you look at the page source you would see the following in the header:
<style type="text/css">
.h1 {color:#000000;}
</style>
You will notice that the default value of #000000 is given for the color. Once this value is changed via the customizer, the new value will be shown. For example, let's say you wanted to change the color to white. In the customizer, you insert the hex value for white, #ffffff, click Save and Publish.
Now in the page source you will see:
<style type="text/css">
.h1 {color:#ffffff;}
</style>
At this point, your live theme customization options should be fully functional (unless the settings you defined in Part 1 explicitly use 'transport'=>'postMessage').
Tip: At the end of this tutorial is a Sample Theme Customization class. This class contains a useful function (which is NOT part of WordPress) called generate_css() that can help you quickly easily generate valid CSS for this step.

Part 3: Configure Live Preview (Optional)

This step is optional, but can dramatically improve user experience. This technique uses a little custom JavaScript in combination with your settings for a faster, more interactive Theme Customizer. If this is not used, then updates are rendered by reloading the entire preview window.
In order to create this custom JavaScript handler, you need to do the following:
1 - Make sure your settings are all configured for live preview ( 'transport'=>'postMessage' )
2 - Create a new JavaScript file (e.g. theme-customize.js) to handle the live changes
3 - Create a hook for 'customize_preview_init' that enqueues the js file
We'll go through all 3 steps in detail...

Step 1: Update Your Settings

First, make sure that any custom settings you've created have 'transport'=>'postMessage' set (see "Adding a New Setting" above). This will disable the automatic refresh behavior when you change that setting, allowing you to define any custom JavaScript handling you like.
Please note that all of WordPress's Theme Customizer settings use 'transport'=>'refresh' by default, so if you want to make the default, built-in Theme Customizer options also take advantage of this, you can easily update their transport method(s) within your 'customize_register' hook function like this:
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
$wp_customize->get_setting( 'background_color' )->transport = 'postMessage';

Step 2: Create a JavaScript File

Next, you need to create a new JavaScript file for all your custom handling. Generally, you'd call this theme-customizer.js and place it in your theme's 'js/ folder, but you can call it whatever you want or place it where you want.
The contents of your theme-customizer.js file might look like this:
/**
 * This file adds some LIVE to the Theme Customizer live preview. To leverage
 * this, set your custom settings to 'postMessage' and then add your handling
 * here. Your javascript should grab settings from customizer controls, and 
 * then make any necessary changes to the page using jQuery.
 */
( function( $ ) {

 // Update the site title in real time...
 wp.customize( 'blogname', function( value ) {
  value.bind( function( newval ) {
   $( '#site-title a' ).html( newval );
  } );
 } );
 
 //Update the site description in real time...
 wp.customize( 'blogdescription', function( value ) {
  value.bind( function( newval ) {
   $( '.site-description' ).html( newval );
  } );
 } );

 //Update site title color in real time...
 wp.customize( 'header_textcolor', function( value ) {
  value.bind( function( newval ) {
   $('#site-title a').css('color', newval );
  } );
 } );

 //Update site background color...
 wp.customize( 'background_color', function( value ) {
  value.bind( function( newval ) {
   $('body').css('background-color', newval );
  } );
 } );
 
 //Update site link color in real time...
 wp.customize( 'link_textcolor', function( value ) {
  value.bind( function( newval ) {
   $('a').css('color', newval );
  } );
 } );
 
} )( jQuery );

As you can see from the example above, a single basic handler looks like this:
wp.customize( 'YOUR_SETTING_ID', function( value ) {
 value.bind( function( newval ) {
  //Do stuff (newval variable contains your "new" setting data)
 } );
} );

Step 3: Enqueue Your JavaScript

Finally, you simply need to ensure your JavaScript is enqueued.
To ensure that the file is loaded only on the Theme Customizer admin screen (and not your live website), you should use the customize_preview_init hook.
For example...
/**
 * Used by hook: 'customize_preview_init'
 * 
 * @see add_action('customize_preview_init',$func)
 */
public static function mytheme_customizer_live_preview()
{
 wp_enqueue_script( 
    'mytheme-themecustomizer',   //Give the script an ID
    get_template_directory_uri().'/assets/js/theme-customizer.js',//Point to file
    array( 'jquery','customize-preview' ), //Define dependencies
    '',      //Define a version (optional) 
    true      //Put script in footer?
 );
}
add_action( 'customize_preview_init', 'mytheme_customizer_live_preview' );

Sample Theme Customization Class

This sample shows one potential implementation of a basic Theme Customization class that can be easily incorporated into any existing theme. This example class even makes use of the postMessage transport method for live JavaScript-based Theme Customizer previews.
Please note that this class should be used in conjunction with the sample theme-customize.js file exampled earlier in this tutorial.
<?php
/**
 * Contains methods for customizing the theme customization screen.
 * 
 * @link http://codex.wordpress.org/Theme_Customization_API
 * @since MyTheme 1.0
 */
class MyTheme_Customize {
   /**
    * This hooks into 'customize_register' (available as of WP 3.4) and allows
    * you to add new sections and controls to the Theme Customize screen.
    * 
    * Note: To enable instant preview, we have to actually write a bit of custom
    * javascript. See live_preview() for more.
    *  
    * @see add_action('customize_register',$func)
    * @param \WP_Customize_Manager $wp_customize
    * @link http://ottopress.com/2012/how-to-leverage-the-theme-customizer-in-your-own-themes/
    * @since MyTheme 1.0
    */
   public static function register ( $wp_customize ) {
      //1. Define a new section (if desired) to the Theme Customizer
      $wp_customize->add_section( 'mytheme_options', 
         array(
            'title' => __( 'MyTheme Options', 'mytheme' ), //Visible title of section
            'priority' => 35, //Determines what order this appears in
            'capability' => 'edit_theme_options', //Capability needed to tweak
            'description' => __('Allows you to customize some example settings for MyTheme.', 'mytheme'), //Descriptive tooltip
         ) 
      );
      
      //2. Register new settings to the WP database...
      $wp_customize->add_setting( 'link_textcolor', //No need to use a SERIALIZED name, as `theme_mod` settings already live under one db record
         array(
            'default' => '#2BA6CB', //Default setting/value to save
            'type' => 'theme_mod', //Is this an 'option' or a 'theme_mod'?
            'capability' => 'edit_theme_options', //Optional. Special permissions for accessing this setting.
            'transport' => 'postMessage', //What triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)?
         ) 
      );      
            
      //3. Finally, we define the control itself (which links a setting to a section and renders the HTML controls)...
      $wp_customize->add_control( new WP_Customize_Color_Control( //Instantiate the color control class
         $wp_customize, //Pass the $wp_customize object (required)
         'mytheme_link_textcolor', //Set a unique ID for the control
         array(
            'label' => __( 'Link Color', 'mytheme' ), //Admin-visible name of the control
            'section' => 'colors', //ID of the section this control should render in (can be one of yours, or a WordPress default section)
            'settings' => 'link_textcolor', //Which setting to load and manipulate (serialized is okay)
            'priority' => 10, //Determines the order this control appears in for the specified section
         ) 
      ) );
      
      //4. We can also change built-in settings by modifying properties. For instance, let's make some stuff use live preview JS...
      $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
      $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
      $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
      $wp_customize->get_setting( 'background_color' )->transport = 'postMessage';
   }

   /**
    * This will output the custom WordPress settings to the live theme's WP head.
    * 
    * Used by hook: 'wp_head'
    * 
    * @see add_action('wp_head',$func)
    * @since MyTheme 1.0
    */
   public static function header_output() {
      ?>
      <!--Customizer CSS--> 
      <style type="text/css">
           <?php self::generate_css('#site-title a', 'color', 'header_textcolor', '#'); ?> 
           <?php self::generate_css('body', 'background-color', 'background_color', '#'); ?> 
           <?php self::generate_css('a', 'color', 'link_textcolor'); ?>
      </style> 
      <!--/Customizer CSS-->
      <?php
   }
   
   /**
    * This outputs the javascript needed to automate the live settings preview.
    * Also keep in mind that this function isn't necessary unless your settings 
    * are using 'transport'=>'postMessage' instead of the default 'transport'
    * => 'refresh'
    * 
    * Used by hook: 'customize_preview_init'
    * 
    * @see add_action('customize_preview_init',$func)
    * @since MyTheme 1.0
    */
   public static function live_preview() {
      wp_enqueue_script( 
           'mytheme-themecustomizer', // Give the script a unique ID
           get_template_directory_uri() . '/assets/js/theme-customizer.js', // Define the path to the JS file
           array(  'jquery', 'customize-preview' ), // Define dependencies
           '', // Define a version (optional) 
           true // Specify whether to put in footer (leave this true)
      );
   }

    /**
     * This will generate a line of CSS for use in header output. If the setting
     * ($mod_name) has no defined value, the CSS will not be output.
     * 
     * @uses get_theme_mod()
     * @param string $selector CSS selector
     * @param string $style The name of the CSS *property* to modify
     * @param string $mod_name The name of the 'theme_mod' option to fetch
     * @param string $prefix Optional. Anything that needs to be output before the CSS property
     * @param string $postfix Optional. Anything that needs to be output after the CSS property
     * @param bool $echo Optional. Whether to print directly to the page (default: true).
     * @return string Returns a single line of CSS with selectors and a property.
     * @since MyTheme 1.0
     */
    public static function generate_css( $selector, $style, $mod_name, $prefix='', $postfix='', $echo=true ) {
      $return = '';
      $mod = get_theme_mod($mod_name);
      if ( ! empty( $mod ) ) {
         $return = sprintf('%s { %s:%s; }',
            $selector,
            $style,
            $prefix.$mod.$postfix
         );
         if ( $echo ) {
            echo $return;
         }
      }
      return $return;
    }
}

// Setup the Theme Customizer settings and controls...
add_action( 'customize_register' , array( 'MyTheme_Customize' , 'register' ) );

// Output custom CSS to live site
add_action( 'wp_head' , array( 'MyTheme_Customize' , 'header_output' ) );

// Enqueue live preview javascript in Theme Customizer admin screen
add_action( 'customize_preview_init' , array( 'MyTheme_Customize' , 'live_preview' ) );