You can use two solutions for this but avoiding the 2nd solution with arg() function is better according to Drupal docs. You should arg() function wherever possible because resulting code is hard to read.

1) Use menu_get_object function

$term = menu_get_object('taxonomy_term', 2);
if ($term) {
  // User is on a taxonomy term page

2) Use arg() function

if (arg(0) ==  "taxonomy" && arg(1) == "term" && is_numeric(arg(2)) && arg(3) == "") {
  // Taxonomy term page

If you want to have a taxonomy for countries inside your website, you can download the XML file attached with this post and then download the Taxonomy Import module from here
After downloading, you can see two new tabs for import/export on taxonomies page.
Go to import -> Target Vocabulary (Select "Your Desktop Direct File Upload") -> Browse file to upload -> From dropdown select format of file to XML -> then click on import.

You can see that a new vocabulary has been created, then later you can change the name of vocabulary .

Download File: 

Possible Use-Case : You want to show a list of "Countries" and there related "Cities". But you want only related cities to be shown on the page .
 To do this place country as parent term and all the cities as sub-term. So construct a vocabulary like this :

- Delhi
 - Rajashtan
- Chandigarh
- Gujrat

- Alabama
- Alaska
- Georgia
- Illinois

Then use simple module called "Simple Hierarchical Select" or you can also use "Hierarchical Select"
But hierarchical select has more functions but if you have taxonomy related task only then you can use only SHS as for the above use-case.

Now go to the content type -> manage fields -> select term reference-> simple hierarchical select Or create a field like this if you haven't created.
Now go to your views or create a view if you haven't already created => select the "your-field-name" (hierarchical select ) from filters and force it to some depth. Expose this filter for users.

Then it will show first country name and then child term which are city names.


Subscribe to RSS - Taxonomy