Intro To Taxonomy CSV (Part 1): Import And Export Structured Terms

The Taxonomy CSV module allows site builders to import and export taxonomy terms using a CSV file. This allows content creators to define large vocabulary lists in Excel or Numbers, export the spreadsheet to CSV, and then import it into a website. Another benefit of using this module is the ability to import a large list of terms by adding terms into a text area. This makes managing vocabulary lists a lot easier in the early stages of site building.

In this tutorial, we’ll look at how to import and export parent and child terms. When you import terms using Taxonomy CSV, there are a lot of options on the import page. We’ll import terms using the least amount of configuring and use a simple CSV example.

Getting Started

Before we begin, go download and install the Taxonomy CSV module.
If you use Drush, run the following command:

$ drush dl taxonomy_csv

How To Import Terms

The first piece of functionality that we’ll look at is how to import a group of terms. Manually adding terms through Drupal’s administration UI can be tedious because you have to enter terms one at a time. Using Taxonomy CSV, you can import terms via a CSV file or by copying terms directly into a text area.

It is highly recommended that you always backup the database before importing terms into a website. If the import goes wrong, you can revert to a working copy.

Import Flat Vocabulary

Let’s now import a bunch of terms into the Tags vocabulary. The first group of terms will be a flat list.

You should have the Tags vocabulary if you installed Drupal using the standard installation profile.

1. Go to Structure -> Taxonomy and click on the “CSV Import” (admin/structure/taxonomy/csv_import) tab in the top right corner.

2. In the first vertical tab (1. What do you want to import?), select the “Structure” radio button.

Fig 1.0

3. Scroll further down and select “Flat vocabulary” from within the “Type of structure” radio list.

Fig 1.1

4. In the second vertical tab (2. Where are items to import?), copy the list below into the “Terms to import” text area.

Drupal
WordPress
Joomla
Symfony

Fig 1.2

5. In the third vertical tab (3. How is your source formatted?), you can configure CSV settings and text format for custom fields and the fixed description field on the term. For this example, we’ll leave everything as the default settings.

6. In the fourth vertical tab (4. Which vocabulary do you want to import into?), you decide which vocabulary the terms will be imported into. Select the “Import in an existing vocabulary” radio button and Tags from the “Vocabulary choice” drop-down list.

Finally, check the “Automatically delete all terms of the selected vocabulary before import” checkbox. This will delete the existing terms and replace them with the imported ones.

Fig 1.3

7. Scroll to the bottom of the page and click on Import. Once the import process is complete you should see the following message.

Fig 1.4

Import Simple Tree

In the last section, we imported terms as a flat list. However, in the real world terms within a vocabulary often have some sort of structure, so in this section we’ll import terms as a tree structure.

Our end goal is to import a list like the one below:

Fig 1.5

Let’s now import a structured tree into the Tags vocabulary.

1. Go to Structure -> Taxonomy and click on “CSV Import” (admin/structure/taxonomy/csv_import).

2. In the first vertical tab (1. What do you want to import?), select the “Simple tree” option from within “Type of structure” and check the “Keep order of terms” checkbox.

Fig 1.6

3. In the second vertical tab (2. Where are items to import?), copy the list below into the “Terms to import” text area.

Drupal
Drupal,Version 7.x
Drupal,Version 6.x
WordPress
WordPress,WordPress 3.5.x
WordPress,WordPress 3.1.x
Joomla
Joomla,Joomla 3.x
Joomla,Joomla 2.x
Symfony
Symfony,Symfony 2.2
Symfony,Symfony 1.4

Fig 1.7

4. Select the same options in the fourth tab (4. Which vocabulary do you want to import into?) as we did in step 6 in the last section.

5. Once you’re ready, scroll to the bottom and click on Import.

How To Export

The final item I want to demonstrate in this tutorial is how to export terms. We spent all this time importing terms now let’s look at how to export them out.

1. Go to Structure -> Taxonomy and this time click on the “CSV Export” (admin/structure/taxonomy/csv_import) tab.

Fig 1.8

The look and feel of the export page is the same as the import. Major sections of the form are separated into vertical tabs.

2. In the first vertical tab (1. What do you want to export?), select “Term names” from the “CSV format” radio list. You can also select a specific vocabulary or just export them all.

3. Scroll to the bottom and click on the Export button.

The module will generate a CSV file and copy it into the files directory. Once the export is complete a message will appear with a link to the CSV file.

Fig 1.9

In part 2 of this series, we’ll look at importing terms with custom fields

If you have any questions, please leave a comment.

4 thoughts on “Intro To Taxonomy CSV (Part 1): Import And Export Structured Terms”

  1. hey your description is great but I am trying to import taxonomy with Images. i have created a menu which grabs taxonomy terms as menu items and shows Image when i hover over the taxonomy name.

    Trucks
    RAM-1500(With Image )
    RAM-2500 (With Image )
    dodge 150 (image)
    Sedan
    Accord(image)
    Civic(image)

  2. Hi Ivan, I have a csv with rows containing school type – region – commune – school name. Is it possible to import this using this tool. I can’t work out how to do this, attempting seems to crash my installation. It seems for every row I would have to do something like this:

    Junior school
    Junior school, north region,
    Junior school, north region, main commune,
    Junior school, north region, main commune, happy days junior school

    That seems like it will be as slow as typing all the unique entries into the vocabulary.

    Any idea?

    Ed
    Junio

Leave a Comment

You have to agree to the comment policy.

This site uses Akismet to reduce spam. Learn how your comment data is processed.