Hi,
I am trying to extract the tid from the child product to construct a url.
What I have is a vocabulary with terms and subterms (children).
What I want to do is to extract the tid and the tid from the child, so that I can make a link from this.
For example:
Vocabulary
- term 26
--Child term 168
What works is to extract the tid 26 from above example when I load an apropriate node, but I have no idea how to get the second term too.
And then there is of course the problem that sometimes I have no child and sometimes I have. But I think I can solve this if I have a solution for extracting the child tid.
The code I use that works for the first tid is:
$vid = 2; // Set this to the vocabulary is you want the term to come from
// Are we looking at a single node
if ( arg(0) == 'node' && is_numeric(arg(1)) ) {
$nid = (int)arg(1);
$terms = taxonomy_node_get_terms($nid);
foreach($terms as $term) {
if ( $term->vid == $vid ) {
$tid = $term->tid;
$workshops = "
" ;
Thanks for any help
Comments
Try this
Look at this post
http://drupal.org/node/216763
You can adapt this code to "climb up" the database getting child and parent terms. If you need to do this for a range of vocabularies you can use db_fetch_object
Thanks a lot for this. I
Thanks a lot for this. I will try it.
But one question. I think the code I am using right now extracts the term id from the URL so that there is no call to the database nessecary?
Does that not also mean that there must be the child term somewhere in the URL that I could extract? Because the first term ID I can fetch with this code.
possibly
if the address is taxonomy/term/parentid/childid
then arg(2) is the parentid and arg(3) is the childid. I have no idea what your url is but you could use
$_Get['q'] to get the URL and then arg(3) should be the childid, if indeed that is how you have set up the URL
I am actually not sure how
I am actually not sure how the URL is set up, but since my code gives me the parent id there must be the child id somewhere too, I presume.
I am just calling a node ( well I open it) and this node has a tid which is a child id of a parent id.
What I do is I use these id's to construct a link that calls a view and passes these tid's as filters.
How would I use $_Get['q'] ?
If I just had a funktion to print out these two ids I would be all set, since it is no problem anymore from there.
try
print $_GET['q'] to see the address