Grab Node ID from URL of Current Page?

How do I grab the Node ID in the URL of the current page and pass it through a link?

1) The URL on the current page is in the format:  website.com/parameter/parameter/parameter and the third parameter is the Node ID.
2) I want to grab that Node ID and put it into a link on that page like <a href="/node/add/contenttype?field_demo_id_reference=123">Link</>

The screen capture illustrates this.Screen Capture
sandshakimiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongCommented:
try:

<?
if ($node = menu_get_object()) {
 $nid = $node->nid;
}
?>

then:

<a href="/node/add/contenttype?field_demo_id_reference=<?=$nid?>">Link</>

ref:
http://drupal.stackexchange.com/questions/6638/get-a-node-id-from-the-url
http://drupal.stackexchange.com/questions/38779/how-to-get-nodeid

Not really use Drupal before but hope this works
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sandshakimiAuthor Commented:
Where should I insert this PHP?
0
Ryan ChongCommented:
in your php page, you can put:

<?
if ($node = menu_get_object()) {
 $nid = $node->nid;
}
?>

before the link:

<a href="/node/add/contenttype?field_demo_id_reference=<?=$nid?>">Link</>

will this work for you?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

sandshakimiAuthor Commented:
So be more specific about where I'm putting the link:

In a View, under Header, I have added a Global: Text area, changed the format to Full HTML.

And in the text area, I've put the link.

Should I put the PHP in there?
0
Ryan ChongCommented:
>>In a View, under Header, I have added a Global: Text area, changed the format to Full HTML
You can try that if it works.

If it didn't you may post your scripts here
0
sandshakimiAuthor Commented:
Thanks, I used a variation of this.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.