programmatically getting custom node belonging to a term
This might be helpful

How to use EntityFieldQuery

It works great for me. As far as the other question is concern, there are many ways of doing this. the simplest would be below, provided that you are accessing link in your question:

&lt;?php
    $arg0 = arg(0);
    $arg1 = arg(1);
    $arg2 = arg(2);

    echo $arg0; //this will echo 'taxonomy'
    echo $arg1; //this will echo 'term'
    echo $arg2; //this will echo 2 (term ID)
?&gt;


Info about arg() can be found here: arg()