0

Using WordPress Multisite Subdomain with Hostmonster

For those who used WordPress multisite feature already know that you can choose between subdirectory (example.com/blog) or subdomain (blog.example.com) install after the new installation.

There are two exceptions however. First exception is that your WordPress installation is over one month old. You can only do the subdomain install after activating the multisite feature. Second is that you are running WordPress on localhost, or your hosting provider doesn’t support the subdomain setup for WordPress (more on that later). In these situations, you can only do the subdirectory install.

In order to use the subdomain install, your hosting provider needs to support creating a wildcard subdomain (*.example.com). If  your provider doesn’t support the wildcard subdomain, it will return an error while trying to create the subdomain in the subdomain section of the cPanel.

If you are using Hostmonster and have only one domain in the account, the wildcard subdomain needs to point to the root of the public _html directory.

In the Hostmonster cPanel, navigate to Domain > Subdomains or just type “subdomains” in the Find field at the left side of the cPanel homepage and click Subdomains to enter the subdomains section.

Click the subdomains link under the Domains panel

Click the subdomains link under the Domains panel

Or just enter "subdomain" into the Find field and click the subdomains link

Or just enter "subdomain" into the Find field and click the subdomains link

Once in the Subdomains section, enter the wildcard (*) into the name field of the subdomain. The next step is very important. cPanel will automatically fills up the Document Root field with whatever the characters you entered into the subdomain name field, in this case “wildcard”. You need to empty that field to make it to point to the root of the document.

cPanel will automatically fills out the Document Root field with "wildcard"

cPanel will automatically fills out the Document Root field with "wildcard"

You have to empty the Document Root field manually

You have to empty the Document Root field manually

After the information are correctly entered, click Create button to create the wildcard subdomain.

From now on you could create the new subdomains directly in WordPress without going through the cPanel, unless the new subdomain you want to create is not WordPress-based site.

Add a new subdomain within WordPress admin

Add a new subdomain within WordPress admin

0

Begin Migrating to the WordPress Multisite (Update 5)

This morning I moved all the files on the site to a subdirectory and replaced with a simple maintainance notification. This blog, however, I decided to stay it online to give migration status update within this post. After the migration completed, I will replace this blog with a brand new look.

Look forward to it.

Update 1: WordPress installed on the main site robbychen.com.

Update 2: Deleted all of the subdomains of the site except blog.robbychen.com for providing the migration status update temporarily.

Update 3: Finally enabled WordPress multisite feature. It took me almost 1 hour to figure out the wildcard subdomain issue. If you only have one domain in your account (which is the primary domain), you don’t have to enter anything in the directory path field when creating the wildcard subdomain. Apparently, cPanel always add the word “wildcard” to the directory field automatically. Make sure you drop this word so that the directory field is empty and press submit. It will create the subdomain without any error.

Update 4: The migration is almost finished. All I need to do is to migrate this blog into the multisite network.

Update 5: The migration finally completed. This blog is now a part of robbychen.com multisite network. I still need to convert my old main site robbychen.com to WordPress. I will keep you updated with the conversion process in a new post.

0

A few Updates and some Information regarding SOPA / PIPA

I had not posted anything for a while. So in this post, I will talk about the upcoming updates for this blog as well as this website as whole and my opinion for the SOPA/PIPA bills.

During the last few weeks, I have learned the ins and outs of WordPress, including WordPress multi-site feature, themes, plugins, etc.

In the coming weeks, I will install WordPress to my main site, robbychen.com, create a portfolio theme or a child theme out of an existing portfolio theme out there, and make my main site as my portfolio to showcase the web development and video projects I finished in the past.

I’m also probably to remove this blog as well as MySQL database that associated with it to migrate it to the main site using the multi-site feature.

That’s all for the update. Now for my opinion about the SOPA / PIPA bills.

In the last couple of days, I read so much about these two bills and how bad they are. I even joined the blackout protest yesterday on this domain. I always thought that the Internet piracy is illegal until I stumbled across this TED presentation.

It basically stated in the presentation that the large media companies have been behind these copyright bills since decades ago. They don’t want us to become the producers and share contents around. They want us to become consumers and just be the “couch-potatoes”. I think that’s why the Internet piracy is born to encourage people to share contents with each other.

Therefore, even if these two bills passed into laws, there will still be a large army of pirates to challenge these companies and find another way to share contents.

0

Working with jQuery and CakePHP

Recently I’m working with CakePHP and SQLite to develop a gallery for a client. This is going to be my first CakePHP app.

While I’m working on the admin section, I wanted to allow the client to see the image once the image filename field is out of focused so that he could see if it’s the correct image.

The only JS library included with CakePHP is Prototype. Fortunately, the latest version of CakePHP (1.3.11 as of right now) allows us to include with other JS library. I included jQuery with the help of Js helper:

var $helpers = array("Js"=>array("Jquery"));

The above code is included with the whatever controller(s) you want to use this helper. In my case is galleries_controller.php and images_controller.php.

Then I just need to add the following code into the corresponding views, in my case is some of the admin views (admin_edit.ctp, and admin_add.ctp):

echo $this->Js->set("imageLoc", $this->Html->image("0"));

echo $this->Js->get("#GalleryCover")->event("blur", "$('#cover').html(window.beta.imageLoc.substring(0, window.beta.imageLoc.length-12) + 'images/' + $('#GalleryPath').val() + '/thumb/' + $(this).val() + '" />');");

Note that I used image object in the Html helper to generate a dummy img tag so that I could precisely get the image folder location in the webroot folder. Then I used set object in the Js helper to transfer this generated PHP value to Javascript variable “imageLoc”. The second line is self-explanatory if you know jQuery. Here is the documentation in the CakePHP Cookbook for you to review.

In the jQuery code section of the second line, I used the substring function to remove the last 12 characters in the img tag (0″ alt=”" />). And used the html function to include the generated code into the “cover” div. Every time the “GalleryCover” field is blurred out of focus, the image inside the “cover” div would change to the corresponding images.

If you need more information on how to use CakePHP generated Javascript variables, please refer to the second article in the reference section.

Do you have any other tips on how to incorporate jQuery into CakePHP? Please share them in the comment below.

Reference

0

Remove AIO SEO related Columns with Greasemonkey and jQuery in WordPress

2

Creating an even Simpler Framework than MVC – Part 2

I discussed a little bit about this mini-framework in part 1. Today I rewrote the whole code for the index.php to be more configurable, and I added another folder for storing PHP pages. And yes, it includes the automatic page title generation.

It’s up to you to create other folders for the includes, images, and other files, but the PHP pages folder is a must have. Without this folder, the framework will grab the original page without process through the framework.

Let’s begin.

I need to first introduce the basic folder structure for the framework:

Note that I’ve included lessPHP inside the css folder to make writing styles easier.

The .htaccess file in the root folder is exactly the same as part 1‘s:

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>

However, the one in the pages folder is different:

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteRule ^(.*)$ ../$1 [L]
</IfModule>

As those of you who understands the Apache better knows, the above code acts like access rejection. It means that whenever someone tries to access the pages folder or one of the files within it, this code will automatically rewrite the URL to the root folder. Note the difference between rewrite and redirect.

The pages folder is kinda like public or webroot folder, except it’s only used for PHP pages, not for images, stylesheets, Javascripts, or any other files.

Now the most important file, index.php. This file is placed in the root folder, and contains the most important code in the whole framework. I also added page title generation in this file as stated before.

[php]
<?php
	// Variables configuration
$rootDir = dirname(__FILE__) . "/";
$mainDir = "pages/";
$appDir = $rootDir . $mainDir;
if (isset($_GET['url'])):
	$url = $_GET['url'];
	$path = $appDir . $url . ".php";
else:
	$path = $appDir . "index.php";
endif;
if (!file_exists($path)):
	$path = $appDir . 'notfound.php';
	$title = "Page not found";
endif;

	// Set page title
	// First set the page title from the the title variable from the individual page if presented
foreach (file($path) as $content):
	if (strstr($content, "title")):
		if (strstr($content, """)):
			$quote = """;
		else:
			$quote = "'";
		endif;
		$titleVar = explode($quote, $content);
		$title = $titleVar[1];
	endif;
endforeach;
	// Process the URL as the page title if title variable is not set
if (empty($title)):
	$urlPath = explode("/", $_SERVER['REQUEST_URI']);
	$titleVar = (string)$urlPath[sizeof($urlPath)-1];
	$title = "";
	for ($i=0; $i < strlen($titleVar); ++$i):
		if ($titleVar{$i} == strtoupper($titleVar{$i})):
			$title .= " ";
		endif;
	$title .= $titleVar{$i};
	endfor;
	$title = ucfirst($title);
endif;

	// Include the neccesary pages
include_once $rootDir . 'includes/header.php';
include_once $path;
include_once $rootDir . 'includes/footer.php';
?>
[/php]

As you have noticed, I’m using URL to auto-generate the page title. You can also set the page title for each page using the $title variable.

The $mainDir variable is configurable, so you can rename the pages folder to whatever you want.

That’s it. If you don’t count the img, css, and js folder and files inside them, the files for the framework would be total of 7 files.

Here is the completed files.

If you have any issues working with this mini-framework, leave a comment below and I will happy to help you.

1

Creating an even Simpler Framework than MVC Framework – Part 1 (Updated)

Update: I rewrote the code for the framework and added page title generation as well, take a look at part 2.

After building and digging through the source of the simple MVC framework provided by Anant Garg, I was able to discover the true nature of the MVC framework. Actually, I’m able to modify his framework to an even simpler framework which just use View and a little Controller in the MVC (Model-View-Controller) with no database connectivity.

The primary use for the MVC pattern is to work with the database. However, sometimes we don’t need to use database to creating a web site. According to my own knowledge, the Model is used to interact with the database and the Controller uses logical to process the database.

I stated that I need to use “a little” Controller because it also controls which page to display and sends it to the View.

In this simple framework (and perhaps all of the MVC frameworks), the most important file is .htaccess which controls the URL. Here is the content of the file copied directly from Anant’s post:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?url=$1 [PT,L]

</IfModule>

Note that this .htaccess file needs to place in th root directory of your web site instead of public folder because we will be creating a framework that has no directory. You can create public folder or webroot folder if you want, but make sure to change the following code accordingly.

The above code converts the URL path to the url query. For example, the URL http://localhost/mvc/test would be converted to http://localhost/index.php?url=mvc/test.

Next step is to create the index.php file which used to process the url query:

<?php
	if (isset($_GET['url'])):
		$url = $_GET['url'];
		$path = "{$url}.php";
	else:
		$path = "home.php";
	endif;

	include_once 'includes/header.php';
	if (file_exists($path)):
		include_once $path;
	else:
		include_once 'notfound.php';
	endif;
	include_once 'includes/footer.php';
?>

This is what I called “reverse include”, because I had always been include header and footer manually on every page until I found CakePHP MVC framework.

I also stated that this framework will not have any folder. Well, to include header and footer, you need to create an includes folder to place all the repeatable scripts, unless you really want to be disorganized :) .

Congratulation, you just created a mini framework. Note that this framework is used for small websites or personal sites where the database is not used at all. This means that it doesn’t have a back-end to edit the page directly on the server.

However, there is also an advantage to it. You don’t need to include the header and footer manually when creating a new page. It will include them automatically. It also can direct to the custom page if the specified page is not found.

About the title issue: I haven’t found a solution to set the title on individual page yet. Right now the title in the header is static. I will update this post once I find a solution to this issue.

Feel free to discuss this framework with me in the comment below.

0

Write CSS3 with Understandable Variables with LessPHP – Part 3

LessPHP allows you to use variables in your CSS stylesheet for the repeatable blocks of code.

In part 2, I provided you with the content of var.less. This part I will give you an example on how to use this .less file to write your own stylesheet. The provided example is based on the final project of this post on the Nettuts+.

First off, here is the folder structure for this example:

Example folder structure

Folder structure for the example

From top to bottom, they are:

css - folder

less - folder

lessc.inc.php in less folder - LessPHP compiler

main.less in less folder - source file to compile to CSS stylesheet

@import 'var';

body, html {
	@dimension(100%;100%);
}

body {
	@center;
}

#box {
  @bg-color(#e3e3e3);
  @dimension(400px;200px);
  @transition(all;1s);
  border: 1px dashed #666;
  margin: auto;
  cursor: pointer;
  position: relative;
 	:after {
 		@dimension(70%;10px);
 		@box-shadow(0;9px;20px;rgba(0,0,0,.4));
	  content: '';
	  position: absolute;
	  bottom: 0;
	  left: 15%;
	  z-index: -1;
	}
	> div {
  	@bg-color(#e3e3e3);
    @dimension(100%;100%);
    @transition(all;1s;ease-in-out);
    position: absolute;
    top: 0;
    left: 0;
    font: 45px/200px bold helvetica, arial, sans-serif;
    text-align: center;
  	:first-child {
	    position: relative;
  	  z-index: 2;
    }
 }
 :hover {
 	@rotate(;rotateY(180deg));
 	> div:first-child {
  	opacity: 0;
 	}
	div:last-child {
  	@rotate(rotateY(180deg));
 	}
 }
}



var.less in less folder - contains the LessPHP variables which I already provided it to you in part 2

index.php in css folder – contains the compile script which provided in part 1

main.css in css folder – contains the compiled CSS styles

index.php in root folder – contains the inclusion of main.css in css folder

Note that some of the code are directly copied from the above source. Also, in order to completely experience this example, you need to use Chrome or webkit compatible browsers.

Feel free to ask any question you have regarding the above code in the comment below.

2

Write CSS3 with Understandable Variables with LessPHP – Part 2 (Updated)

Update: I updated the code to add more explanation on the Flexible Box Model related properties.

LessPHP provides CSS stylesheet to have variables for reducing repeatable code in order to improve productivity.

In the last part, I talked about how to installing the LessPHP and general folder structure of an one-page web app using LessPHP. This part I will provide you with var.less which includes some CSS3 properties discussed in this post on Nettuts+.

Note that all of the code used LessPHP and CSS3 syntax. If you don’t understand the LessPHP syntax yet, here is its full documentation.

@bg-color(@color:red) {
 background-color: @color;
}

@bg-size(@xWidth:100%;@yWidth:100%) {
 background-size: @xWidth @yWidth;
 -o-background-size: @xWidth @yWidth;
 -webkit-background-size: @xWidth @yWidth;
 -moz-background-size: @xWidth @yWidth;
}

@border-radius(@radius:4px) {
 border-radius: @radius;
 -webkit-border-radius: @radius;
 -moz-border-radius: @radius;
}

 // Accepts start, end, center, baseline, stretch. Default to stretch
@box-align(@align:center) {
 -moz-box-align: @align;
 -webkit-box-align: @align;
 box-align: @align;
}

 // Accepts horizontal, verticle, inherit. Default to horizontal
@box-orient(@orientation:horizontal) {
 -moz-box-orient: @orientation;
 -webkit-box-orient: @orientation;
 box-orient: @orientation;
}

 // Accepts start, end, center, justify. Default to start
@box-pack(@pack:center) {
 -moz-box-pack: @pack;
 -webkit-box-pack: @pack;
 box-pack: @pack;
}

@box-shadow(@x:1px;@y:1px;@blur:3px;@color:#292929) {
 -webkit-box-shadow: @x @y @blur @color;
 -moz-box-shadow: @x @y @blur @color;
 box-shadow: @x @y @blur @color;
}

@box-shadow-multi(@shadows:1px 1px 3px green, -1px -1px 3px blue) {
 -webkit-box-shadow: @shadows;
 -moz-box-shadow: @shadows;
 box-shadow: @shadows;
}

@center {
 display: -moz-box;
 display: -webkit-box;
 display: box;
 @box-orient;
 @box-pack;
 @box-align;
}

@columns {
 display: -moz-box;
 display: -webkit-box;
 display: box;
 @fill(@fill:1) {
 box-flex: @fill;        // Accepts either 0 to be as is or an integer to fill the entire area of parent box
 -moz-box-flex: @fill;
 -webkit-box-flex: @fill;
 }
}

 // This is the test/default styles
@defaults {
 @dimension;
 @bg-color;
 @center;
}

@dimension(@width:100px; @height:100px) {
 width: @width;
 height: @height;
}

@resize(@direction:both) {
 resize: @direction;    // Value can be both, horizontal, vertical, or none
 -moz-resize: @direction;
 -webkit-resize: @direction;
}

@rotate(@rotateX:rotateX(0deg);@rotateY:rotateY(0deg);@rotateZ:rotateZ(0deg)) {
 transform: @rotateX @rotateY @rotateZ;
 -webkit-transform: @rotateX @rotateY @rotateZ;
 -moz-transform: @rotateX @rotateY @rotateZ;
}

@text-outline(@outterColor:black;@innerColor:white) {
 text-shadow: 0 1px 0 @outterColor, 0 -1px 0 @outterColor, 1px 0 0 @outterColor, -1px 0 0 @outterColor;
 color: @innerColor
}

@text-overflow{
 .on(@type:ellipsis;@width:500px) {
 text-overflow: @type;        // text-overflow accepts two values: ellipsis, and clip which didn't seem to work in Chrome
 -o-text-overflow: @type;
 width: @width;
 overflow:hidden;
 white-space:nowrap;
 }
 .off {
 white-space: normal;
 width:100%;
 }
}

@text-shadow(@x:1px;@y:1px;@blur:3px;@color:blue) {
 text-shadow: @x @y @blur @color;
}

@text-stroke(@length:3px;@outterColor:black;@innerColor:white) {
 -webkit-text-stroke: @length @outterColor;
 color: @innerColor;
}

@transition(@property:padding;@duration:0.4s;@easing:ease-in) {
 -webkit-transition: @property @duration @easing;
 -moz-transition: @property @duration @easing;
 -o-transition: @property @duration @easing;
 transition: @property @duration @easing;
}

Some of the above code is commented to give you more information about the acceptable values. One of the code blocks, @defaults, provides you the basic layout for an element. It allows you to add other CSS properties to enhance its layout. As the comment stated, it also provides you with a test layout to test an element.

You also can use the above code as a reference to CSS3 since some people think that CSS3 is harder and more complex than CSS2

You probably noticed that there aren’t multiple background images and @font-face, that’s because I can’t figure out how to integrate them with LessPHP yet.

Do you have any problem using the above stylesheet? Leave a comment below and I will respond to you quickly.

1

Write CSS3 with Understandable Variables with LessPHP – Part 1

LessPHP is the PHP version of LessCSS, a CSS stylesheet language which is relied on Node.js web server. All LessPHP need is the PHP server.

In this part I walked you through the installation of LessPHP compiler and general folder structure for a one-page web app using LessPHP. In the next part, I will give you some CSS3 properties with parameters which have easy to understand variables.

The installation of LessPHP is easier than you think. After you download its source from github, the only step is to copy lessc.inc.php into your web app folder and included in the page. Here is the basic structure for the folder:

Folder structure for the one-page web app

Folder structure for the one-page web app

Below is the explanation for each file and folder from top to bottom:

web app is the root of the web app.

styles contains lessPHP files and compiled CSS stylesheets.

less contains lessPHP compiler and less source.

main.less relates to main.css which I discussed below. It contains the styles information that will output to main.css.

var.less contains the lessPHP variable definitions which is imported to main.less using @import.

index.php in the styles folder is used to compile the less source to CSS stylesheet. It contains the following code:

<?php
 // Convert LESS to CSS styles
 include_once 'less/lessc.inc.php';
 try { lessc::ccompile('styles/less/main.less', 'styles/main.css'); }
 catch (exception $ex) { exit($ex->getMessage()); }
?>

main.css is the compiled stylesheet.

index.php contains the code of your web app but first you need to include the index.php from the styles folder:


<?php
 include_once 'styles/index.php';    // Include the LessPHP compiler in the beginning of this file
?>

The above is general folder structure of mine for one-page web app. If you need to create a multi-page web app, you can create a include folder and include the lessPHP compiler to header.php or somewhere similar.

When you edit the stylesheet, you need to only edit the .less files and it will re-generate main.css file once the page is loaded.

In the next part, I will provide you the content of var.less which mentioned above that includes some CSS3 properties for your reference or you can use it as a template.

If you have any question about this part, post them in the comment below.

Pages ... 1 2 3 4 5 6 7 8 9 10 11