How to link taxonomy term with its content?
In Drupal 7 you can use l()

  $ch = 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 = $tid AND book.entity_id = $nid")-&gt;FetchField();

  $chap = taxonomy_get_children($ch);
  foreach ($chap as $ca) {
    print l($ca-&gt;name, 'taxonomy/term/' . $ca-&gt;tid);
  }