From a page based on a url of taxonomy/term/##
, how do I properly get the tid (the numeric value in the URL) without using args()
? Is using args() a decent way of doing this?
-
2What is the end goal? In what context do you need the tid for?– kyletayloredJun 27, 2014 at 6:57
-
To sum up, this is one of those questions that, after helpful feedback that made me questioned why and what, I decided to approach this from an entirely different way.– RickJul 2, 2014 at 17:04
1 Answer
From where this page is coming, from core taxonomy or views?.
By default the taxonomy module provide the taxonomy/term/##
callback and views module also provide a default view with the path taxonomy/term/##
.
If you haven't enabled the Taxonomy term view then this page will be the default taxonomy core page, in that case you can use menu_get_object('taxonomy_term', 2)
to get the loaded term.
For arg()
, the document says
Avoid use of this function where possible, as resulting code is hard to read. In menu callback functions, attempt to use named arguments. See the explanation in menu.inc for how to construct callbacks that take arguments. When attempting to use this function to load an element from the current path, e.g. loading the node on a node page, use menu_get_object() instead.
-
-
The position of the object in the path, like
taxonomy(0)/term(1)/##(2)
– msmaniJul 2, 2014 at 17:08