Wordpress custom menu for each user? - php

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.

Related

How to show a node of a content type in two different places with different url and hiding some fields in the one place in drupal?

I have a content type named Ailment, which displays all the ailments of the particular user, when u click the ailment, it goes to a particular node, displaying details and graphs of that ailment which is added by the user, this is fine.
Now in another page I wan to search ailment of the whole site and display the ailments, and when they click the ailment it should show the graphs and should hide some fields which shows only for the particular user..
For ex: user A is having a page where ailments wil be listed, when he clicks the ailment, for example cancer, then it goes to myailment/cancer, where some fields and graphs wil be displaying.. this is fine
Now I am having a another page /topailment, where I have a search box, any user can come and search any ailment, it should display the ailment for example cancer, then it should go to the page, topailment/cancer, where it should display only graphs and hide fields..
Hope I am clear..
I am trying to find a solution but going no where...
Please help
Thank you.
this is possible with Page Manager. It will take some learning, but the best place to start is here:
http://nodeone.se/en/learn-page-manager-part-1-overview
Essentially, you want a node to have two different page displays. There are several ways to do this, but page manager is the most direct for me.
Good luck!
Mike
As is always the case in Drupal, there are many ways you could do this. Two options come to mind immediately:
Use views and create a view with multiple displays to renders your Ailment nodes in different ways.
Create custom display modes using the Display Suite module.
You could even go for a blend of both options by creating additional display modes with Display Suite and rendering those display modes with views.
To do it purely with Display Suite: once display modes are configured, you can enable the 'View mode per node' option made available by Display Suite Extras (bundled with the core module) and pass the view mode as a URL parameter to the node. This way you would link to your node as normal from most pages and from the user page you would link to (for example) node/123?v=personalized to use the personalized display mode.
Which of these approaches you go for probably depends on your familiarity with these modules and what you're already using.
There is a module for that :) . It solves this specific problem and plays very nicely with display suite for hiding modules. You have to create a new view mode, assign it to your content type, select which fields you want to hide for each view mode and then you create a URL in your manage fields section for that particular view mode. https://www.drupal.org/project/view_mode_page

Flexible sidebar database design

In my system I have a flexible layout, where you can place your sidebar left or right (or both). You can add multiple sidebars and then choose which one you want to use for your page, and on which location.
What is the best way to store the items in a sidebar, while maintaining the ability to edit the item configuration per sidebar?
The items consist of a php class in which the config options are passed through to a template file.
My origional thought was to implement some sort of shortcode functionality and add a shortcode to a sidebar_item entry in the database, but this way it wouldn't really be configurable.
If I understand you correctly, you have:
a user, who can place a sidebar where he wants to,
a sidebar, that can contain some elements,
items, that can belong to each sidebar to each user,
files to handle items of different types.
and every user has his own sidebar with his own content.
I can propose tables:
users in which users are defined by some id,
sidebars in which you say which user it belongs to, and if it is left or right,
item_types where you say which template and/or configuration files should be used,
items in what type it is (from item_types), so you know which template to use, then in which sidebar (from sidebars) it is, maybe what position it is (first, second, ...).
You should create relations between:
sidebars and users on user id so selecting user you could know which sidebar(s) he owns,
items and sidebars on sidebar id, so knowing sidebar you know which items are in it,
item_types and items on item type so you know how to handle it,
Perhaps, in items you can also store configuration variables that you could pass to template.

Drupal route based node content

I'm new to Drupal and have a basic question which I cannot find a good answer to. I am trying to dynamicly determine the contents of my website based on a selection made by the user and keep the selection displayed in the routing for SEO purposes.
It's a website for a Restaurant with multiple franchises.
What i'm trying to do is the following:
The user visits my website and gets a splash screen presented with the available franchises or a textbox to enter his postalcode
Upon selecting he enters the main website with the navigational structure adapted to the selected franchise. For example: domain.com/city/, domain.com/city/menu, domain.com/city/menu/dishes, domain.com/city/contact, ...
The contents of all nodes are based upon the city the user selected. Some franchises have extra nodes which should be displayed in the main navigation aswell.
What I have thought about so far is to try to accomplish this with taxonomy but I really have no idea where to start. Parts of the nodes will be the same for all franchises other parts will be different. Menu item prices will also be different.
This is the first website i'm building using Drupal so any advice is welcome.
Thanks!
It will be impossible to explain it all here but yes it is possible to select your content based on user input in Drupal. You will need to look into Views & Panels.
In Views you can use arguments to narrow to a specific taxonomy. With Panels , an argument can be retrieved fron the URL and passed to the Views in order to display the results.
There are a lot of resources available, Merlin of Chaos, the author of the Views & Panels modules has written a book about it. There are video tutorials online. Your best bet is to start with drupal.org.

Magento - Multi-domain & Filters

We're looking to build in a filter to our Magento site with drop down choices for the first two options, a selection box for price plus a colour chooser.
Firstly how easy is it to fetch the info for the first two dropdowns from the database so the first box is populated with the first category then the second box populated with the choices for that particular category? (and then change if someone changes the first selection)
Secondly how easy is it to set up a separate filter for each site so it only fetches info for the corresponding store and doesn't show products from other stores?
The filter will only have to show the products when you press a 'find' button so I guess it's a case of building up the search query?
Thoughts and ideas on this would be great, only been working with Magento for a month so still not sure of it's full capabilities.
Thanks
For the second part Magento already shows only products relevant to a given store. When you set up the stores (in System > Store Management) you have the option of giving it a unique "root category". Creating root categories is easy, in Catalog > Manage Categories.
The first part requires some programming work. From your previous questions it looks like you have a good understanding of Javascript so AJAX is not a problem. I don't know how familiar you might be with PHP, listing products will require you create a new module, with it's own controller, that forms a collection from the selected category. Collections make their own queries so you don't need to write a lick of SQL, and they have functions for exporting as JSON or XML so you don't need to write that either. For an experienced programmer it would take almost no time at all.

Drupal 6 dynamic menu item

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;
}
}

Categories