2

I have created two vocabulary

  1. Program
  2. Topics

I want to load the topics based on the program selection.

It looks like category and subcategory.

I created some program like java, .net, PHP and I created some topics like session (php), inheritance(java), cookie(php).

So now I want to list all the topics which are coming under a particular program.

Can you tell me which drupal function used to get all the terms under parent terms.?

Note: taxonomy_get_children not working because I am using two vocabularies

  • You've not defined how your 2 taxonomies have a relationship. If you've not done this, you need to find out how to do that. See drupal.stackexchange.com/questions/96280/…. – Shawn Conn Jun 22 '16 at 20:23
  • Hi ..I mentioned its look like category and subcategory.so topics contain program term id as parent. – Kabali007 Jun 23 '16 at 6:11
  • Without explaining how the relationship is defined (e.g. term reference field within your taxonomy entities), no one can give you an answer to question. – Shawn Conn Jun 23 '16 at 6:20
  • ya i used term reference in topics.it point to the program vocabulary – Kabali007 Jun 23 '16 at 6:46
0

You'll need to load your content's term references and then load those term entities so you can follow your chain of taxonomy terms. There's many ways to do that; taxonomy_term_load_multiple() is one such function.

$tids = array();

// @TODO: Use the $nid that corresponds with your node 
// @TODO: Replace field_program & field_topic with your taxonomy ref field name
$node = node_load($nid);
foreach ($node->field_programs[LANGUAGE_NONE] as $term) {
  $tids[] = $term['tid'];
}
$programs = taxonomy_term_load_multiple($tids);

// @TODO: Iterate over $programs and retrieve 
// topic tid references from $program->field_topic[LANGUAGE_NONE]
0

You can add code in template.php as theme_preprocess_page()
if(arg(0) == 'taxonomy' && arg(1) == 'term') { $tid = (int)arg(2); $term = taxonomy_term_load($tid); $arrTermId = taxonomy_get_children($tid); $arrData = taxonomy_select_nodes(array_keys($arrTermId), $pager = TRUE, $limit = FALSE, $order = array('t.sticky' => 'DESC', 't.created' => 'DESC')); $arrContent = node_load_multiple($arrData, $conditions = array(), $reset = FALSE); print_r($arrContent); }

In $arrContent you will get values of all the nodes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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