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: Drupal Translation






0 Comments:
Post a Comment
Links to this post:
Create a Link
<< Home