Drupal 6 - L'importation des termes de taxonomie en mode facile

Posted by: 
najib0s

I just discovered a very handy api to import taxonomy.
It is included with the taxonomy csv module in the file taxonomy_csv.api.inc

I needed to do something very simple import some terms into a vocabulary (no hierarchy, no related terms, just tags..). I already had my csv parser to create my nodes so I did not use the interface of the module. Since I had my terms in an array I just needed to prepare them and import them with this api function :

<?php
  
//prepare
  
$terms = array(
    array(
'name' => $data[20]),
    array(
'name' => $data[21]),
    array(
'name' => $data[22]),
    array(
'name' => $data[23]),
    array(
'name' => $data[24]),
    array(
'name' => $data[27]),
    array(
'name' => $data[28]),
  );

  foreach (
$terms as $term) {
    
//voc id
    
$term['vid'] = ASSOC;
    if (
$term['name']) {
      
//Voici la fonction
      
taxonomy_csv_term_import($termTAXONOMY_CSV_EXISTING_UPDATE_REPLACE);
    }
  }
?>

Mais ce n'est pas ça, les modules de l'api peuvent faire beaucoup plus. Importer les vocabulaires au total, créer des hiérarchies, des termes connexes, ...
Toute l'aide est dans les commentaires des fichiers.

Add new comment

Who are you?


By knowing who you are you will be directed to a page where we have displayed all our drupal services relevant to your professional identity.