How can I print taxonomy name with published node count with a custom link?
eg: Taxonomy term-a (23) Taxonomy term-b (10) Taxonomy term-c (55)
I need to link each of them to a separate page.
I found this below code to print taxonomy term with count. but now how to make to print specific taxonomy term with it's node count? so that I can link it to a page later, so if I repeat the same code with different term ids to have multiple terms with its count.
<?php
$vid = 23; // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
$parent = 130;
$terms = taxonomy_get_tree($vid, $parent, -1, 1);
foreach ( $terms as $term ) {
$count = db_result(db_query("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} t ON n.nid = t.nid WHERE t.tid = %d AND n.status = %d", $term->tid, 1));
{
print '<div>' . l($term->name, "taxonomy/term/$term->tid") . " ($count)" . '</div>';
}
}
?>
Can someone please help me?
__HAD TO ANSWER HERE AS I CAN'T AT THE BOTTOM__
This is it!!!
Took a while to write this code... :(
<?php
$tid = 100;
$term = taxonomy_get_term($tid);
$name = $term->name;
$result = db_result(db_query("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} t ON n.nid = t.nid WHERE t.tid = %d AND n.status = %d", $term->tid, 1));
print '<div><a href="http://example.com/">' . $name. " ($result)" . '</a></div>';
?>
Change: 100 at the second line of above code to your specific taxonomy id, that's it and repeat the same for different tid.
And make sure to change the link at the bottom from (http://example.com/) to your (custom link).
Thanks a lot to all, let me know if this code can be fine tuned further...