0

I have problem when our taxonomy term is linked with node but when i am clicking on term they go front page of site instead of current page our code given below:

$ch1 = db_query("SELECT th.tid FROM taxonomy_term_hierarchy th 
  INNER JOIN taxonomy_term_data td ON th.tid=td.tid
  INNER JOIN field_data_field_books book ON book.field_books_tid = th.tid
  WHERE td.vid = '6' AND th.parent = $ch AND book.entity_id = $nid
 ")->FetchField();

$chap1=taxonomy_get_children($ch1);
foreach($chap1 as $ca1){
    $link = l($ca1->name, 'node/' . $ca1->nid)."<br>";
    print $link;
}

How to handle this problem?

  • Can you add more detail on your problem like where is your code? Moreover, Your query can be replaced by Drupal core function : see this thread – Payou Feb 14 '14 at 13:20
  • i am using this code in block but problem is that its only have tid values not nid – Adi Feb 14 '14 at 13:21
0

"$ch1" contain tids.

The function "taxonomy_get_children($ch1);" retrieve all children term id and not related nid...

You can retrieve all nid linked with a term with this function taxonomy_select_nodes

I will suppose $ch1 contain your tids in an array

foreach($ch1 as $tid){
    $nids  = taxonomy_select_nodes($tid);
    $nodes = node_load_multiple($nids);
    foreach($nodes as $node){
        $link = l($node->title, 'node/' . $node->nid)."<br>";
        print $link;
    }
}

I can't test this code, if it's valid tell me and i will remove this line :)

  • please tell proper code i am new in drupal – Adi Feb 14 '14 at 13:36

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.