Menu items that are not links


/ Published in: PHP
Save to your folder(s)

The following code lets us designate "menu links" that will not actually link anywhere.


Copy this code and paste it in your HTML
  1. <?php
  2. function phptemplate_menu_item_link($item, $link_item) {
  3. if ($item['path'] == '<none>') {
  4. $attributes['title'] = $link['description'];
  5. // Here you can specify a '#' link or wathever you want:
  6. // return '<a'. drupal_attributes($attributes) . 'href="#">'. $item['title'] .'</a>';
  7. return '<span'. drupal_attributes($attributes) .'>'. $item['title'] .'</span>';
  8. }
  9. else {
  10. return l($item['title'], $link_item['path'], !empty($item['description']) ? array('title' => $item['description']) : array(), isset($item['query']) ? $item['query'] : NULL);
  11. }
  12. }
  13. ?>
  14. <?php
  15. /*
  16. * As a nice extra, we can also add additional help text to the menu item edit page. For that * you will need to implement a very small module that implements form_alter.
  17. * The module itself doesn't need anything more than the following code snippet:
  18. */
  19. function example_form_alter($form_id, &$form) {
  20. if ('menu_edit_item_form' == $form_id) {
  21. $form['path']['#description'] .= ' ' . t('Enter %none to have a menu item that generates no link.', array('%none' => '<none>'));
  22. }
  23. }
  24. ?>

URL: http://drupal.org/node/143322

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.