I'm looking for a way to display the node id somewhere on all displayed instances of a given content type. It doesn't need to happen in any particular way, but it would sure help my users to be able to see the node id, as we use it to track physical objects.

I would imagine that there are a couple of ways to do this, so if someone could outline the options that would also help.

I've tried something like

$node_id = arg(1);

To no avail, as I can only put this in each individual node instead of all nodes for a given content type.


If you're trying to do this for a certain content type, and have a custom theme you're using with your site, I'd suggest modifying the template file for that content type to print out the node id somewhere below or above the content.

However, if you're not very good with theming a really creative way to do it is by creating a view block and enabling it for that content type. Then the node id can be displayed on the side of the content. It can be nothing more than a line... doesn't have to be obtrusive.

To do the above:

  1. Create a new view and call it something like 'Node id display' (uncheck the page version of the view and only create a block version). Restrict it to the content type you want here, and make sure it's displaying fields, rather than titles, summaries or whatever is the default
  2. Under the view's 'Fields' section, remove all fields that appear by default and only dislay the 'Content: Nid' field. You can change the label to be something like "Node id" instead of 'Nid' if you prefer.
  3. Under the 'Advanced' section of the view, add a contextual filter of 'Content: Nid', and in the configurations, select for it to 'Provide a default value' if a filter is not present. From the drop-down, select 'Content ID from URL'
  4. Either through a context or from the block's admin page, enable the new block for your specific content type... place the block on a sidebar, above the content, below the content... anywhere you want.


Hope this helps!

  • 1
    I tried most of this. I should mention that I'm on drupal 5.8. I'm sure that this was way different back then, no? I've followed your steps as much as I can, but I am not seeing the results I'd expect. – jml Dec 4 '12 at 4:10
  • Oh no! That's why it's so important to share your Drupal version. I've used Drupal 6, and contextual filters are similar there, but have never used Drupal 5. Is that the part you couldn't set up? Setting up the contextual filter is crucial to get it to show up for the current node. I'll go ahead and tag your question with the Drupal version too, in case there are any Drupal 5 gurus keeping up with that queue. – Boriana Ditcheva Dec 4 '12 at 14:36
  • Unlikely, eh? :) – jml Dec 4 '12 at 23:31
  • So is it step #3 you're having trouble completing? – Boriana Ditcheva Dec 5 '12 at 17:33
  • Many of the steps are different in D5. Not just #3. – jml Dec 5 '12 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.