In the first part of this series we looked at setting up the basics of the conversions script, config files, user imports and discussed the importance of planning each stage out and how to go about it.

In this section we will be looking at importing the categories from Wordpress into Joomla. You will be glad to know this part of the series should be a bit shorter to read. Though no less complicated, it is also the 3rd step of the conversion, and we only need to run the article import and the clean up after this.

One of the problems with the conversion is that Wordpress and Joomla, as you would expect do things differently, this is comes to light in the categories import and presents us with the first big decision of the entire import process. The problem is, that whilst in Wordpress all Categories can be a parent without a child, Joomla requires that you have both a section and a category.
This leads us to make the choice whether to create a single “placeholder” parent section, and then make all of our categories from Wordpress into Joomla categories, or whether to create all our Wordpress categories as Joomla sections and those without children, create a placeholder category under the section.
Finally, Joomla only allows for 2 levels, Section >> Category, whereas Wordpress allows, for children to be parent categories themselves giving a never ending hierarchy so we aren’t going to be able to have say “technology” >> “Apple” >> “iPhone” so we have yet another decision to make, we will either have to cut out the middle man, make the middle category section, or make them all sections with a generic “general” category beneath them.
In this case I have decided to include a function that will check the following:

  • If the category is a parent
  • If the category has children
  • How many children and levels it has
  • Restructures the categories, to either have child, to be child and brings them into a singular line

As such you will likely need to manage and change these through the Joomla Administrator UI after the conversion, as you may wish to get rid of some of the parents, (i.e. Technology >> Apple >> iPhone becomes Technology >> iPhone therefore either eliminating the need of the Apple category or making it obsolete in this example.

This scheme should work, it also means that each singular parent category is going to need a child, so lets say you had a category called “Foo”, we will then create a category under it called “bar” we will in this example however, name the category the same as the section, this will be somewhat confusing when you first look at it, however it at least maintains some sanity and continuance from your Wordpress set up.

If you want to make life easier it may be worth editing your category structure in Wordpress before the conversion this, will make life easier at the end of the day. We will no matter what repeat the section as a category, so it works in the same way as Wordpress.

I hope that wasn’t too confusing, it’s really quite simple, it’s just a matter of coming up with the correct or best worked solution for you. This is how I have decided is the cleanest way to operate and gives us a closer 1 to 1 relationship for Wordpress vs Joomla.

Finally I should mention that we will be making another “map” table which will give us a map of the categories again, so we can reference, the old category id and get the new category id, we will also record the section id, so we can drop all of the content into the content tables correctly.

So without further ado, her is the code.

<?php
error_reporting(E_ALL);
//
// Include The configuration file
//
include('config.php');
 
//
// Create a new connection to the Wordpress Database
//
$db = new  ezSQL_mysql($wp_db_user, $wp_db_pass, $wp_db, $wp_db_host);
echo "Initialised WP DB<br/>";
 
//
// Create a connection to the Joomla Database
//
$jb = new  ezSQL_mysql($j_db_user, $j_db_pass, $j_db, $j_db_host);
echo "Initialised JOS DB<br/>";
 
//
// Create a new table in your Joomla database to store the new 
// category and section ID's so that we can map posts and articles to them. We will destroy this table as one of the final steps
//
 
$jb->query( "CREATE TABLE `jos_wp_category_map` (`wp_cat_id` INT NOT NULL ,`jos_cat_id` INT NOT NULL ,`jos_sec_id` INT NOT NULL) ENGINE = MYISAM ");
echo "Created Category Map table<br>";
 
//
// This function iterates through the categories and children and updates the ID's
//
function updateCategory($category, $newParentID)
{
	global $db, $jb, $wp_prefix, $j_prefix;
	$children = $db->get_results("SELECT t.term_id as term_id, t.name as tname, t.slug as tslug, tt.description as description, tt.parent as parent FROM ".$wp_prefix."terms AS t INNER JOIN ".$wp_prefix."term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('category') and parent=".$category."  ORDER BY t.name");
 
	foreach($children as $child) {
		updateCategory($child->term_id, $newParentID);
		//Check if we are insterting into 1.5 or 1.0.x
		if($j_version=='1.5') {
			//Insert the latest category 
			$jb->query("insert into ".$j_prefix."categories (title, alias, section, description, published) Values('".$child->tname."', '".$child->tslug."', '".$newParentID."', '".$child->description."', 1)");
		}
		else
		{
			//Insert a matching Category for this top level category (now exists as Joomla Section and Category)
			$jb->query("insert into ".$j_prefix."categories (title, name, section, description, published) Values('".$child->tname."', '".$child->tslug."', '".$newParentID."', '".$child->description."', 1)");
 
		}
 
		// Insert into our temp storage/reference table
		$jb->query("insert into jos_wp_category_map (wp_cat_id, jos_cat_id, jos_sec_id) values(".$child->term_id.", ".$jb->insert_id.", ".$newParentID.")");
 
	}
 
}
 
//
// This query grabs all of the categories from the wp tables, wp stores categories in a taxonomy format, which essentially means that there
// is a multipurpose table which holds everything from categories, to tags, this consists of 3 tables in total, but we just want to grab information
// from 2 of them, term_taxonomy and terms. We could limit this query to grab only what we want, but I use the full query for anyone interested
// in seeing exactly what information is stored for category in Wordpress, more an FYI query than being specific and to the point, and does not harm
// since we will in 99% of cases be grabbing less than 1000 rows.
$categories = $db->get_results("SELECT t.term_id as term_id, t.name as tname, t.slug as tslug, tt.description as description, tt.parent as parent FROM ".$wp_prefix."terms AS t INNER JOIN ".$wp_prefix."term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('category')  and parent=0 ORDER BY t.name");
 
echo "<br/>Categories Selected from WP";
 
//
// Loop through the results array and work our magic
//
foreach($categories as $category) {
 
	//Check if we are insterting into 1.5 or 1.0.x
	if($j_version=='1.5') {
		// Insert the Parent Category into Joomla as a "Section"
		$jb->query("insert into ".$j_prefix."sections (title, alias, scope, description, published) values ('".$category->tname."', '".$category->tslug."', 'content', '".$category->description."', 1)");
		$newParentID = $jb->insert_id;
		//Insert the section as a category of itself
		$jb->query("insert into ".$j_prefix."categories (title, alias, section, description, published) Values ('".$category->tname."', '".$category->tslug."', '".$newParentID."', '".$category->description."', 1)");
	}
	else
	{
		// Insert the Parent Category into Joomla as a "Section"
		$jb->query("insert into ".$j_prefix."sections (title, name, scope, description, published) values ('".$category->tname."', '".$category->tslug."', 'content', '".$category->description."', 1)");
 
		$newParentID = $jb->insert_id;
		//Insert as a category to it's own section
		$jb->query("insert into ".$j_prefix."categories (title, name, section, description, published) Values ('".$category->tname."', '".$category->tname."', '".$newParentID."', '".$category->description."', 1)");
 
	}
 
	// Insert into our temp storage/reference table
	$jb->query("insert into jos_wp_category_map (wp_cat_id, jos_cat_id, jos_sec_id) values(".$category->term_id.", ".$jb->insert_id.", ".$newParentID.")");
 
	//Jump into the recursive function and update all of the subcategories and align them in a Joomla! style of section vs Category
	updateCategory($category->term_id, $newParentID);
 
}
 
echo "Category Import completed";
?>

The code above is not perfectly tuned but I ran out of time because work became exceedingly busy and I didn’t have the time to put in to refine the code to my usual standards. However it is functional and does the job we intended.

It inserts the category, grabs the first sub-category and inserts that, and then enters a recursive function in order to find each of the sub-categories of the first sub-category until it runs out of records to go through. This could be simplified to make the recursion hit immediately which i will do once I wrap this into a downloadable script, otherwise enjoy. The content will be following close on the heels.

Rate this:
2.1

When you start to learn PHP programming you will need to first start with an editor to write your code with and there are plenty of them out there for you to choose from and use. There is no editor that is right for everyone and it comes down to a matter of preference and in most cases what you first started learning withm is what you tend to stick with, it just becomes familiar and easy, but I always encourage expanding on what you have and trying new things.

In this tutorial/Review I am going to list some of the most commondly used PHP editor tools and some information about them. Hopefully any new coders can then try out some of them and decide on what is best for them.

Edit Plus

http://www.editplus.com/
Personally this is the editor that I use the most, out of a desire for change and a completely freeware application I have tried changing but always find myself relying on this brilliant application.

I first started out coding ASP in Edit Plus, so was more than use to it’s workflows and styles, so that when I transitioned to learning PHP I was able to adapt fairly easily with Edit Plus.

There are a stack of features in the application that I wont go through, I will let the creators of the application do that for you, However some of the things that I found incredibly useful when learning and still use to this day is the “ClipText” feature.

The ClipText allows you to either load a predefined list, add to an existing or create your own, this allows you to simply double click an item from the list which will insert the related code directly into the code you are editing at the current cursor location. When learning this feature is incredible because it lets you essentially set up a list of repetitive snippets of code, to save time and effort.

I used this mostly for database connections and functions that I have created. I can quickly click on “DB Connection” from my list and then fill in the connection details and I am away, saves several lines of typing code and a lot of time across a large project.

The syntax highlighting is again very easy to understand and follow and you can also edit or add your own syntax highlighting or download other people’s set from the Edit Plus website.

The application is free to use for 30-days and then can be bought for a small fee after that, and I advise in purchasing it as it is a fantastic application, and the authors have done a great job.

NotePad++

http://notepad-plus.sourceforge.net/uk/site.htm
First of all NotePad++ is completely freeware which is the first advantage that the application has over EditPlus. I have recently started using NotePad++ more and more, it offers a further flexibility over Edit Plus and shares many of the same features. This means that in general it is a win over Edit Plus.

There are some code quirks to it and it doesn’t always handle spacing in some documents as well as other applications (Think Windows notepad) However this is only on the odd occassion and over all it handles things very well.

The one feature I find myself very attracted to in Notepad++ is the collapsable routines. This feature, if you have indented your code correctly (otherwise sometimes it guesses a little) will automatically create a tree style + next to your IF and other routine statements within you code. This is extremely useful when trying to find end points of these routines and in general for making your work area tidier as you code.

Again it has many other features but I am only touching on the most obvious and useful. If you are just learning to code I would highly reccomend this as your editor, as it will be easier than transitioning at a later date, and it offers a lot for new coders and developers.

Continue Reading ->

One of the great things about starting up this site is that the mere process of creating the site is providing me with so great content to share with you. The creation of a site, that has a specific purpose and fluid content, instead of a rigid niche content, provides the opportunity for experimentation.

This experimentation may be in the form of the form of design, layout, advertising, structure and even the content system that is used for the site.

In this case you may notice that I am still experimenting with design, I am a coder and definitely not a designer, instead I pay others to do design for me or work with open source or free designs. However I have settled on the content delivery system, which is Wordpress.

This brings me along to a topic which I will discuss in part now, and that will be an ongoing theme and series on this site, which I think may be of use to some of the readers of the site. The topic in a nut shell is which is the best CMS for you.

The short answer to the question is, “how long is a piece of string?” because it depends on the needs, I use quite a few for the various sites I run, but always tend to come back to Wordpress and Joomla, they are outstanding applications.

The long answer we will discuss as this series continues, and I will approach it from an angle of SEO and useibility the main theme being the SEO and “monetization” of websites, because recently I completed an experiment with one of my sites and found some pretty unexpected results. Ones I think are worth talking about. So stay tuned as I finish tweaking the site and I will get the information to you.

Dan

Rate this:
1.8