0

I want to list only parent terms in order to rearrange the orders like /admin/structure/taxonomy/vocabulary_name. Given url have displayed all terms included child terms. I want to avoid term terms. So i've tried to create custom page. I've tried below code but i can't make it work.

function test_menu() {
  $items['manage_category/%taxonomy_vocabulary_machine_name'] = array(
   'title' => t('Manage category'),
   'page callback' => 'arep_manage_category',
   'page arguments' => array(1),
   'access arguments' => array('administer taxonomy'),
   'type' => MENU_CALLBACK,
 );
 return $items;
}

function arep_manage_category() {
  $category = arg(1);
  module_load_include('inc', 'taxonomy', 'taxonomy.admin');
  $taxonomy = taxonomy_vocabulary_machine_name_load($category);
  $form = drupal_get_form('taxonomy_overview_terms', 'taxonomy_term', $taxonomy);
  return drupal_render($form);
}

I've tried to access this page by vocabulary name. How ot make it work? Is any other idea?

1 Answer 1

0

Firstly you add a cck field named flag for levels to your vocabulary when created, then after that when you import or add terms in this then fill flag value like "My First Level"/"My Second Level". then you can fetch very easily like that..`

/* Get All States From Taxonomies */
  function get_taxonomy_by_flag($flag) {
       $VocabName = "Master Data";
          $myStateArray = array(0=>'-- Select --');
        $Vocabluary = get_vocabulary_by_name($VocabName);
         $query = new EntityFieldQuery();
          $entities = $query->entityCondition('entity_type', 'taxonomy_term')
->propertyCondition('vid', $Vocabluary->vid)    
->fieldCondition('field_flag', 'value', $flag, '=')    
->execute();
if(sizeof($entities)>0)
{       
  foreach($entities['taxonomy_term'] as $tid) {

    $term = taxonomy_term_load($tid->tid);     
    $name=$term->name;
    $myStateArray[$term->field_code['und']['0']['value']] = $name;    
  }   
  return $myStateArray;     
}
else
{
    return 0;
 }    
}

    function get_vocabulary_by_name($vocabulary_name) {
        $vocabs = taxonomy_get_vocabularies(NULL);
         foreach ($vocabs as $vocab_object) {
          if ($vocab_object->name == $vocabulary_name) {
            return $vocab_object;
         }
      }
            return NULL;
      }
     call this function by flag name and you can easily get all parents. because i have used this for **State/District/Block/Village** purpose.
      get_taxonomy_by_flag('STATE');

hope this helps you lot...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.