-3

I am using below code :

 echo "<h1>".Volume."</h1>";
$tid=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 = '0'  AND book.entity_id = $nid
")->FetchField();
print $tid->Name;

$child=taxonomy_get_children($tid);
 foreach($child as $t){

$url = "taxonomy/term/$t->name";
    print '<a href="'.$url.'">'.ucwords($t->name).'</a><br>';


    }

they show volume 1,volume 2,volume 3 and they have linked problem is that when i am click on volume 1 they highlighted and show no link but other volumes are show linked in normal form

0

I can only advise to use the available API functions.

To build the link use the l function:

$link = l(ucwords($t->name), 'taxonomy/term/' . $t->tid);

You can also pass in an options array, so to add an active class to the link when the link url points to the current page, you could use something like this:

$options = array();
if (arg(0) == 'taxonomy' && arg(1) == 'term' && arg(2) == $t->tid) {
    $options = array('attributes' => array('class' => 'active'));
}
$link = l(ucwords($t->name), 'taxonomy/term/' . $t->tid, $options);

Also, this kind of code shouldn't be mixed directly in a template, especially not the database query. Have a look at the answers to this question for more insight: Preprocess functions and template files

  • i don`t have a FTP access just i have site login access i am applying this code they give PDO object error – Adi Feb 11 '14 at 11:27
  • @user25762 Where or how do you add the code? – berliner Feb 11 '14 at 11:38
  • $tid=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 = '0' AND book.entity_id = $nid ")->FetchField(); print $tid->Name; $child=taxonomy_get_children($tid); foreach($child as $t){ $options = array(); if (arg(0) == 'taxonomy' && arg(1) == 'term' && arg(2) == $t->tid) { $options = array('attributes' => array('class' => 'active')); }; $link = l($t->name, 'taxonomy/term/' . $t->nid,$options)."<br>"; print $link; } – Adi Feb 11 '14 at 11:45
  • @user25762 Please refrain from posting unasked code and instead reply to the questions. What you just posted doesn't help at all. – berliner Feb 11 '14 at 11:48
  • i am using your code in the foreach loop and its declare in l function same code use as you given – Adi Feb 11 '14 at 11:54

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.