I have Login menu item, and I want to hide it from uathenticated users, I try to find solutions and fount this:
Wordpress Stackexchange
But for my opinion creating two separate menus is not very good idea. Maybe exists another way? Thanks!
This can be done with CSS alone. When a user is logged in, WordPress adds the class 'logged-in' to the page's body tag.
In the menu builder, you can specify a class for an individual menu item in the same place that you set the label and title. For example you could set the class to 'logout-hide'. screenshot:
If the 'class' options is not visible, which it is not by default, turn it on in the 'Screen Options' area. See the bottom row of options in this screenshot:
Now, in your CSS you could use the following CSS rule to hide this item when users are logged in:
body.logged-in li.logout-hide {
display:none;
}
This same approach could be used if you wanted to hide a logout item when logged in, and hide a login item when logged out.
A note about css specificity: You might find that even after you set the rule above, the item is not hidden. This is likely because another rule is overriding your new rule and setting the 'display' property to something visible. For example, if your menu has an ID applied to it (say, 'menu-header-menu' maybe) you will probably have to add that to your rule. i.e:
body.logged-in ul#menu-header-menu li.logout-hide {
display:none;
}
Let us know if you have any problems.
If you don't want to create two seperate menus, you will have to create a custom menu walker. But honestly, creating two seperate menus is the correct way to do it, and it's probably the easiest way too.
Alternatively, you could add a class to the menu items you want to hide, and hide them using either JavaScript and CSS for users that are not logged in, of course, that's not a very good solution.
I was trying Mere Development's way and theoretically it should work however I was using Chrome. Make sure you disable Chrome's cache under DevTools
Related
I was wondering, is it possible to give a registered user to create his own menu based on his chosen categories for the website on WordPress? Let's say he chooses which menu items he wants to see & only sees those menu's when logged in.
This is not a built-in feature, but yes, this would be possible on a custom WordPress site (i.e. WordPress.org, not WordPress.com), and there are a lot of different ways you could structure it.
It would not be trivial to implement, however.
My initial approach would be to have an actual WordPress menu hold all possible items, and then store user preferences as to which of the items are shown or hidden. On their user profile edit page, you could output the menu items as a checkbox list, and then store their selection as a user option. On the rest of the site, when you output the menu, you'd first pull that user option, then output the menu items manually one at a time if they have the option for that item checked.
There are of course other ways, but they would be similarly complex -- well beyond copying and pasting a code snippet, or me typing up a solution for you here.
In the pages .tpl.php of my theme i can find several lines like
render($action_links)
displaying whole pages with a single command. Sometime i saw that the render argument is a block from my theme .info, but other times i see arguments i cannot identify that render default pages or elements of drupal.
How it works? And where i can find a list of default displayable pages?
In particular, i needed to display the content of the default drupal page "add content" in one of my pages, and i'm pretty sure i can do it using this render method, but i cannot find the correct argument.
EDIT: I found something like
drupal_render(node_add('NODE_TYPE'));
that seems to allow the display of a node add form, but what i need is the main add content page, containing the list of all the type of nodes that a user can add.
Are you new to Drupal? When I read your post, I'm almost sure that you have missed something with the Drupal's working. The variables you found in render() functions are "calculated" somewhere else in the code (in the modules part for the most).
You cannot find a list of constant variables to display them just like this.
I found this article about these mysterious variables that are rendered and I hope it will help: http://newsignature.com/articles/the-magic-behind-drupals-render-elements
If you just want to display the "add content" form somewhere on your site, just call its path (node/add).
EDIT AFTER CLARIFICATIONS:
First of all, you can set on which page you want the user lands after login. (I don't know why you're still talking about user profile template. Maybe I missed something again.)
But if I did understand what you're trying to achieve, I'll do that:
Create a menu (or simply use the "Navigation" menu that seems to be exactly what you need) with all the actions users can do. And I'll place this menu in the main content region. Do create a menu, go to Administration>Structure>Menus>Add menu. And add links like "node/add/article" or "node/add/news" or "node/add/page" or whatever your content-types are.
Place this menu in the region you want. If you want it to be like the main content of the page, place it in the main container. To do so, go to Administration>Structure>Blocks> Drag and drop your menu in the right region and Save.
Configure this block to appear only on the front page (the first page on user arrives after logged in) if you want so. To do so, in the Blocks administration page, click on "Configure" next to your block and check "show block on specific pages: Only the listed pages" and write down <front>
Create roles and permissions for your different sorts of users. That will automatically show them the links they are allowed to see. To set permissions, go to Administration>People>Permissions and check in the "Node" section which content-type each role can create.
I hope I didn't forget anything. Please tell me if it is clear enough.
I am running Joomla and using the ChronoForms plug component to create Forms.
I have a problem in that I want to set menu items on a menu in Joomla but want to make use of querystrings so more than one menu item might have the same Form Name but a different querystring. However it isn't possible to use querystrings in menu items with ChronoForms.
One possible solution I am investigating is to do away with querystrings and just check on Form Load which menu item has been selected and then process the form accordingly.
Has someone any ideas how to do this?
I am not sure what you are asking here, but i you wish to have multiple menu items pointed to the same form, you can do this by manually editing the menu item alias. Am I following what you are trying to accomplish?
Look at the menu link created by ChronoForms, when you add it to a menu (without querystring). You can use that as a base for an 'external URL', where you can add whatever you want to it.
I'm trying to find a way to add a custom field for users in Wordpress, but I don't want this field to be seen by the users. It'll be entered and viewed by an admin, but it shouldn't be shown on the registration page or their profile page.
Is there an easy way to do this? If so, may I be pointed in the right direction?
You can use the add_user_meta() function to add any metadata you would like.
In order to display it only to admins level, you should use one of wordpress´s conditional tags, in addition to a simple user level check.
I need to create a menu item, which changes its title and link if a user has a certain condition, or not.
Drupal caches all the menues, so i can't really think of a way to do that.
For example, user has a node attached to his profile, menu item is "Create blabla" (link node/add/blabla)
User doesn't have the node, menu item is "Create notblablabla" (link node/add/notblabla)
The best and easiest way is to use hook_menu with param title_callback.
See thedrupalblog.com and drupal.org.
Drupal does not allow for dynamic menu items, but it can hide certain menu items if the user is not allowed to go there. Referring to your example, if you create both the links and use the permission system to restrict the creation of those node types to certain roles, Drupal will only show the menu items if the user has the required role. Maybe that helps in your situation.
Other options are:
write a simple module that shows a single link for all users and redirects to the appropriate page when clicked
create a custom block which displays the correct link based on the current user (make sure the block is not cached)
use javascript like googletorp suggest (although I wouldn't recommend it for the reasons he mentions)
A simple way to do this, would be to use JavaScript. You can alter HTML without much efford using jQuery. This will require that your users has JS enabled, so it's not a perfect solution.
Another option would be to have a single menu item, that linked to a url you created in a module. He you could do the condition check a redirect the user to whichever url he should be redirected to. The only problem with this method would be that the changing the title of the menu item. But you might be able to give a fitting description for both cases. You could also use JS to change the name of the link. That way you would keep the functionality intact without JS but improve the UI for users with it enabled.
I would probably create two menu items, and use the theme system to hide one or the other based on the condition.
It's been a while, but I'd look at:
http://drupal.org/node/223430
http://api.drupal.org/api/function/template_preprocess/6
http://api.drupal.org/api/function/phptemplate_preprocess_page/6
Since this menu item seems to be predicated on user profile information, I would suggest writing a simple module that implements hook_menu_alter() to alter the menu based on your condition. You can then call menu_cache_clear() inside hook_user() to renew the menu cache when the user profile changes.
Have you tried this (inserting your other conditions into the 'if' statement as well of course):
function hook_translated_menu_link_alter(&$item, $map) {
if ($item['href'] == 'node/add/blabla') {
$item['href'] = 'node/add/notblabla';
}
}
You'll probably also have to do this to mark the link as alterable:
function hook_menu_link_alter(&$item, $menu) {
if ($item['link_path'] == 'node/add/blabla') {
$item['options']['alter'] = TRUE;
}
}