Let's say we have a section /latest-projects with a menu block listing nodes sorted descending by their post date. Thus, the first item will often change and be the freshest one. Is it possible to make the /latest-projects alias always link to (= open) the top-most node?

  • Why not you create a block view or page view from Views UI? Probably I did not understand your question well? – Sithu Nov 26 '12 at 7:22

Indeed it is.

Steps you will need to do:

  1. Create a custom module
  2. Implement hook_menu()
  3. Define the route 'latest-projects', and make the menu callback a function
  4. In the custom menu callback function do SQL or whatever to find the latest project (maybe use EnityFieldQuery in Drupal 7)
  5. Use drupal_goto() to then redirect the user to the latest project node

Note in the above solution, a redirect is used to send the user to the project node, but if needed you can also simply render the node on the page as another idea.

  • That makes perfect sense. Would this pick up the translation for current language? – Artur Nov 25 '12 at 18:52
  • Because you are writing the menu callback with custom PHP, you can also add language as a clause in the query to find on projects of the correct language. – wiifm Nov 25 '12 at 19:19

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.