By jaypabs on
I am using the following code to redirect user not login before they can submit source code:
<?php
global $user;
if ($user->uid) {
print "<a href='http://www.sourcecodester.com/submit'>Submit now...</a>";
}
else {
print "<a href='http://www.sourcecodester.com/user?destination=submit'>Submit now...</a>";
}
?>
Now, I want to create a Submit menu but I don't know how to do this in D7. If the user is logged in then the URL should be:
http://www.sourcecodester.com/submit
If not, it should be:
http://www.sourcecodester.com/user?destination=submit
The latter will redirect them automatically to a submit page after they login.
Any idea?
Comments
Roles restriction
If you add a menu as a block to your page, you can restrict the visibility of this block to any user role by visiting the Roles tab at the Block configuration. You could make two menus, one for each role. However, user's will still be able to access both url. I use Panel pages to restrict accessibility. With this you can also make the same page display different items based on the user's status.
I already have Submit link in
I already have Submit link in a block at the right sidebar of my site. I want another Submit menu to appear in the Main Menu on my site together w/ home, programming, blogs, books, articles, etc. Please visitor http://www.sourcecodester.com/ to see what I mean.
So how can I do that?
Make two main menus
Do you mean Submit link or do you want to nest an entire menu in the Main Menu? As far as I know you can't specify visibility on a per link basis. You should make two main menus, one with and one without the Submit link. How do you get your Main Menu to show on your site (block or via theme)?
I want to have a "Submit"
I want to have a "Submit" menu same as other menu on my main menu like "Home, Programming, Blogs, etc"
If the user is logged in (i.e. registered user) then the URL should point to:
http://www.sourcecodester.com/submit
If not (i.e. anonymous), it should be:
http://www.sourcecodester.com/user?destination=submit
I understand your case
Just be clear about whether you mean menu (a set of links) or link. How is your main menu rendered? Do you us a block or is it called by your theme?
I can't believe you did not
I can't believe you did not understand my question. Did you try to visit sourcecodester.com and see the menu there?
If you can see a Home menu, Blog, Articles, etc, that's where I want Submit menu to appear.
I understand your question
If you want my help, then answer my question. Don't repeat yourself.
As what I have told in my
As what I have told in my previous post particularly on this comment http://drupal.org/node/1573058#comment-5988064 I have said that I already have this working on a block. So it means the menu is called in a theme.
Let me know if you still confused.
Thanks for the help.
Ok let's move on
I think there has been a bit of miscom ;-) The fact that you already have block (the one on the right) does not imply that your main menu is called in the theme as you could have another block for that. However, let's move on. I suggest you customise the page template and wrap the main menu in an
ifstatement such that it only shows when a user is logged in (as in your first post). I would then create a second main menu that includes the Submit link and call this in a second wrap (else,elseiforif). You can also try to condition the Submit link only, but that might cause problems with your layout as the link will be outside the main menu's<ul>tags. Make sure you clear your site's cache when customising template files.So it means there is no way
So it means there is no way to add this menu other than editing the themes?
May be this is also how login/logout works. If you are logged in then logout is visible. If you're not logged in then Login is visible.
That's how I supposed this Submit menu will happen. If not logged in the customize the link to redirect to User login.
Anyway thank you for the help.
I suppose
I suppose there is some way you can conditionally append a link to a menu, but I wouldn't know how. As with the login/logout link, that happens automatically. I found this module that might solve your problem: http://drupal.org/project/menu_item_visibility
Thanks
I'm glad to let you know that I found a module that can do it.
For those who would like to do the same thing, here's the link:
It's Menu item visibility
Thanks