I want to create a menu item linked to the edit page of the last article.

I created a view and added filters to get the last article. I added only the field node path to the view.

But how can I get the value of that path field and put it in the URL of my menu item?

3 Answers 3



Create a view that loads the single last published article, style the view to look like your regular node page and then add a link to the view in your menu.

you could get fancier, but this is the least amount of PHP.

  • tank you for the answer , the problem is that i want the menu item to be linked to the edit page of the last article and not to the last article node ! Jul 6, 2015 at 14:19
  • @ProgrammerB your question says something else now, and if you'll edit it, it will become chameleon - something people don't like, and something you should avoid.
    – Mołot
    Jul 6, 2015 at 14:21
  • @Molot , it's mentioned in the question's body ! Jul 6, 2015 at 14:28
  • @ProgrammerB Then clarify. And please try to use proper spelling and interpunction, it really helps readers understand what you mean.
    – Mołot
    Jul 6, 2015 at 14:30

Thank you DeveloperWeeks , i followed your instructions and made the below code , and it's working like a charm :

* @file
* Use this module to get the last NID of a defined Content Type

* Implementation of hook_menu().

function lastnode_menu() {
$items['lastnode'] = array(
'title' => 'Edit ADS',
'page callback' => 'lastnode_edit',
'access callback' => 'user_is_logged_in' ,
'type' => MENU_CALLBACK,
return $items;

* Page callback.

function lastnode_edit ($content_type = '') {
$nid = db_query('select MAX(nid) from node where type = :type', array(':type' => $content_type))->fetchField();
drupal_goto('node/' . $nid . '/edit');

I like user5482's answer, and it is a good one. If you are logged in, and the view is using "rendered entity" instead of "fields", the Edit context link would be accessible from there and you would have your answer in two clicks and no code.

If you truly want one click that goes straight to the edit page, you will need a custom module. You will need to implement hook_menu in your module, and register a static path. In that hook you should define the access callback as using the appropriate drupal permission; I think you want to find the edit instead of the generic access_content.

You will also need to define a custom callback function that will have the dynamic query to find the most recent (published?) node from the database, construct the url, and execute a drupal_goto to take the user there. This way you can have a static address (good for menus) link to a dynamic location (most recent node edit page).

But again, all this custom code work will only save you one click over user5482's answer. Since I cannot think of a reason you would want anonymous users editing nodes, I am guessing this is a menu item for admins only. That extra click shouldn't destroy the ux.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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