0

I have a dropping menu links for the user menu:

My account

  • Profile edit
  • My posts (track)
  • Exit

Here's an example of my code:

  <ul id="userNavigation">
                <li><?php echo l(t("Profile edit"), "user/%/edit"); ?></li>
                <li><?php echo l(t("My posts"), "user/%/track"); ?></li>
                <li class="exit"><?php echo l(t("Exit"), "user/logout"); ?></li>
            </ul> 

I've tried with wildcard %. With a Views module was very easy, but in this case (without views) it's not working. Is any other way so when user clicks on "My posts" will link to user/user_id/track or profile edit that will lead to user/user_id/edit?

1 Answer 1

1

You cannot use menu wildcards like that. You need to use the following code.

  <ul id="userNavigation">
    <li><?php echo l(t("Profile edit"), 'user/' . $GLOBALS['user']->uid . '/edit'); ?></li>
    <li><?php echo l(t("My posts"), 'user/' . $GLOBALS['user']->uid . '/track'); ?></li>
    <li class="exit"><?php echo l(t("Exit"), "user/logout"); ?></li>
  </ul>

The global $user is the user object for the currently logged-in user. Be careful: It is not a fully-loaded user object. If you need that, you should use the value returned from user_uid_optional_load().

1
  • Thank you very much, It's working perfectly! Also thanks for notice! Commented Aug 25, 2013 at 12:47

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.