Found Somehow
Solutions I've found to my most frustrating coding and computing questions
 
 

Friday, August 14, 2009

Retrieving the translation set node ID (tnid) of the current node in Drupal

I'm mildly frustrated that Drupal 6 doesn't have a way to directly reference the current node's ID from a block.

Well, if there is a way, it's buried in documentation and just doesn't exist on the forums.

What I was specifically looking for, however, wasn't the node ID, but the Translation Set Node ID of the current node. I know it has to be available, because I can use it as an argument in the Views module.

Finding the current node's id is easy enough, if a bit silly. You can pull it from the URL, as it is the second argument arg(1). You can do this even if you have friendly URLs turned on.

$current_nid = arg(1);


Easy enough. Now $current_nid is equal to the current node's ID. If that's all you needed, you're in business.

However, what I'm looking for is the tnid, not the nid. We need to write a little query and find the tnid of the current nid. See the below code.

$current_nid = arg(1);

$sql_tnid = "SELECT N.tnid
FROM {node} N
WHERE N.nid = $current_nid";

$result_tnid = db_query($sql_tnid);

$record_tnid = db_fetch_array($result_tnid);

$tnid = $record_tnid['tnid'];


Now, feel free to use the $tnid as you like.

Labels:

Blocked in China

So, due to various incidents, a slew of social networking and related sites have been blocked in China. Easy to use proxies exist out there, but most are, in the least, a pain in the ass, and in the worst are virtually virus ambassadors.

Anyhow, blogger.com is one of the many blocked sites, so I've been absent for a bit. It's still blocked, but I'm just less lazy and feel motivated to start posting again.

There were a lot of comments on my post involving transparent backgrounds on DynamicMenuItems in asp.net. I do want to address those questions as well, so if you're still out there and commented on that post, drop me a line.