Hi all,

I've just jumped into patching together code for Drupal and finally figured out how to get the current node id - it's arg(1). It took me ages to figure that out (I searched high and low for it but finally found it). So this allowed me to grab some voting information that I want to display about a node.

I placed the following code in my node.tpl.php file and it works when I am in a node (/node/24 for example) but when I am on the main page (/node) it just outputs zero for each node.


$nid=arg(1);
$type=node;

  $vote_result = votingapi_get_voting_result($type, $nid, 'points', 'vote', 'sum');
  print $vote_result;

I suppose that this means that my arg(1) is not picking up information per node. Does anyone have any ideas on how to solve this?

Thanks in advance,

Mohamed

- Muslim Content - a Digg like community news site built on Drupal

Comments

nevets’s picture

From node.tpl.php you can get the nid with $node->nid and that way you get the nid for the node currently being formatted. Also you should probably change $type=node to $type='node' to be proper php code.

mohamedn’s picture

Thanks nevets - that worked perfectly.

Now if someone could just tell me how they build this : http://tec.fresqui.com/ ;)