I am struggeling to get my secondary links to appear in a block.
It works fine in page.tpl.php;
foreach ($secondary_links as $link){
print $link;
}
I put the secondary menu items in the same menu as the primary menu items I just changed the parent to under whatever primary menu item they should appear. This works fine because the secondary menu items appear when they should. But.....here comes the tricky part......I can't get it to work in a block. When I make a new block and put the exact same code in the block....it gives an error.
: Invalid argument supplied for foreach() in c:\program files\easyphp1-8\www\includes\common.inc(1175) : eval()'d code on line 3.
I think it doesn't reconise the variable $secondary_links.
I would also like to make the tertiary menu items appear in another block....How would I go about doing that???
Please help
Comments
Display tertiary menu items
Even just displaying them on the site in my page.tpl.php, not in a block, would be fine. How do I display the tertiary menu items seperately on the site?
Tertiary Links
I am also having the same problem. I haven't yet found a solution that will allow for tertiary links to be displayed. Can anyone help?
I got it
I have been working on this problem for a while now and I have found a backway around this problem. If you download the views module you can display any list of links you want.
In my case all my tertiary menu items where blog items for different users. So what I did was add a view in the views module, gave it a name of course, checked Provide Block and set view type to list view. Added a field Node:Title and added a filter Node:Type blog-item and Node: Author name danielle. Then all you have to do is go to the blocks page, find the block you just created and set it to where you would like it to display and turn it on. Then you can configuere it to where you would like it to display in my case that would be in the blog of that particular user.
You can use views to display any list you want by using the category module. In my case that wasn't nessesary so you should check if there is a possibility to just use the views module without the catergory module(that saves a lot of frustration). If you use the category module then just create a container and some categories of the pages you would like to display. Then you will be able to add a filter in a the views module Taxonomy:Terms for ContainerNameHere. Then the block will only display the terms for that category.
So that means you could create different blocks that display different lists of links.
Good luck
Containers
I'm confused by this. Sorry this is my first time with Drupal. I don't really understand the concept. Here's my setup.
Primary_links: link1, link2, link3
Secondary_links link1/sub1, link1/sub2, link2/sub1, link2/sub2, link2/sub3 ... etc
Tertiary_links link1/sub1/subsub1, link1/sub1/subsub2 ...
If I understand what you're saying, you mean I need to set up a category so when the user clicks link1/sub1, the tertiary links block will automatically be displayed underneith? That block will then contain links to the other sub links.
I don't really know how to do this. First off, where do I actually specify the links the block will contain. I don't fully understand blocks I don't think. WHen I create a new block, can I just edit something to list off 4 links. Then in the blocks setting just say "display for only these pages" ?? Maybe i'm not seeing this correctly
views
The first thing you will have to do is download the views module. This module creates lists of nodes....a list of links. With the views module you can make the view(list of links) appear in a block...in the block configuration you can make this block appear on certain pages(see block visibility). So in the end what you have is a block with a list of links which is what you want. Now the only problem is that you will need to make a new view for every set of tertiary links. So that way every set of tertiary links has a block and you can make the different block appear on the pages you want them to.
To get the right tertiary links in a certain block you can use the filters from the views module. The filters filter out all the other links you don't want in the block. With the filters you can say what properties makes these links different from all the other links. But..........if there are no properties that make these particular links different from all the other ones....you will need the category module.
If you download the category module (if you can...do without) you can make each node(page) a category. So a category is just a page in your site. A container is also a page but also groups a set of categories(pages) together. This doesn't really do anything noticable in your site unless you do something with it. You can keep the structure of your site as it is and replace all the secondary links that have tertiary links with a container...the page will stay the same. Then you can add categories to this container which will be your tertiary link pages. If you use the category module you will see in the views module there will appear another filter. Taxonomy : Terms for SecondaryLinkHere. That means you can filter out all the other links except the pages in your container.
You could also use the path module to create custom links like tertiarymenu/page1, tertiarymenu/page2 etc. this way you could make the block display only on the tertiarymenu/* pages. And you wouldn't have to use the category module at all.
Just download the views module and experiment with it. If there is no way to filter out the other links then download the category module. But I'd try doing it withour the category module first.
If you don't want the tertiary links to appear in a seperate area in the site but in a webtree with the secondary links then all this is not what you are looking for....you might even just want to display the primary links block in some area in the site.
Gook luck
Solution
I kind of cheated.
I created the sub links in the menu item, and I created a block that contains the list of links to the sub pages. Then I display it only on pages with a particular path of the sublink that has the tertiary menu. It only work because the item that has the tertiary menu is last on my secondary_links and I positioned the block just below it. Not pretty, but it worked.
The only thing that doesn't work is the active links for the tertiary menu. By not work I mean it never has the class="active" attribute so it doesn't highlight. This is because I hardcoded the links in the block. I'm not sure how you could do this so that it does actually work like a regular menu.
That would work too...but if
That would work too...but if you change the teriary menu items you would have to remember to change the block too.
$secondary_links block
Did you ever figure out how to get the $secondary_links in their own block? I've figured out the tertiary menu problem, but my new problem comes with making things bilingual. My $secondary_links disappear when I switch to French. If I use "Nice Menus" and enable that block however they don't disappear, however I don't want nice menu's. So, I'm thinking if I can get $secondary_links in it's own block it wouldn't disappear when I switch languages. WHen I use the $secondary_links variable however in a custom block, nothing appears.
Any thoughts are greatly appreciated!
I tried doing that
I tried doing that too....but that didn't work for me either. You could to it using the vieuws module like I discribed above. You can use this technique to display any submenu or subsubmenu or subsubsubmenu etc. you want. But I think in your case it would be better to just try fooling around with the page.tpl.php. You should be able to have the same page in french as in english without adding any blocks.
fix?
bcom, can you describe how you got the tertiary links to show up? Are you using the $secondary_links call within your template or did you achieve it by using a block somewhere withing drupal?
In my case, I need it to be extremely easy for non-tech-savy users to add new pages and place them within the menu hierarchy at the secondary or tertiary levels, so I worry that the above mentioned hack using blocks would make things too complicated.
thakns
Catergory module
If you use the category module and the views module you could make all tertiary links appear where they should. If a user where to add another tertiary link it would just appear as long as they put it in the right category (which is not that complicated). If you make a block for every secondary link that shows all the categories in that container even if that container is empty then the user would never have to mess with the blocks or the views module....just the admin. The user would be able to make tertiary links without touching the views module or the blocks as long as they create the page and put it in the right category the link will just appear where it should.
But even without the category module the user wouldn't have to do anything with the blocks or the views module as long as the admin assigns the right properties for the links in a block. For example you can make a block that only shows the links that where made by a certain user or the links that are in a certain container or the links where the author has a certain role or a links with a certain creation time or a certain node type......etc. Just download the views module and play with it a bit. You will see that you can show all kinds of links. You can even show quaternary or quinary links and the user would never have to know how all of that works.
did it work?
inverarityp, i have the exact same problem as the one you described in your "navigation customization" posting (http://drupal.org/node/81642).
Did you manage to make it work with the category and views modules as d.deman described? If yes does it work exactly as you described in your posting or were there any downsides?
Please let me know, it would spare a long and painfull process of trying it all out and then finding that i can`t use it....
thanks,
tobs
You may also want to check
You may also want to check out the thread over at http://drupal.org/node/77099 - I changed the code suggested there slightly and stuck the following code into a PHP-enabled block. I now get a block of my secondary items.
Coming in late, but:
Unless I've misunderstood, that will only show the submenu when you're looking at the respective primary menu item, not when you're in the submenu itself. You can get the root menu ID by taking the first item in the menu trail, like so:
++Andy
Parent Link as Block title
I'm coming in very late on this one, but is there a way to display the parent link as an 'H2' Block title?
Updates
Not in the actual block title area. However, you could set the block title to <none> and then generate your own title in the content area:
Since I'm here anyway, I'll note that the function _menu_get_active_trail() used in the above code has been replaced by menu_get_active_trail() in 6.x - the same name without the leading underscore (_). The menu squad realised that it was a useful function so should be available to external modules, but didn't cater for people who were already using it (which is fair enough, really, because the _ indicates it's private and may change / disappear at any time).
--Andy
Developing Drupal websites for Livelink New Media
++Andy
Almost perfect
Thanks for the reply kingandy, and for the tip on 6.x. I've been using your solution above now for quite some time on a number of different sites now.
As for the title snippet, I was able to get the titles working as advertised. However, is there a way to make them conditional if there are any secondary links on that page? Right now the titles will show regardless if there are any secondary links to show with it.
I tried wrapping the code into the if statement (below) to no avail:
Any ideas?
On 5.x, the item returned by
On 5.x, the item returned by menu_get_menu has a 'children' element (described as "A linear list of the menu ID's of this item's children"). You can probably add a count() to the if() clause. Something like:
--Andy
Developing Drupal websites for Livelink New Media
++Andy
Correction
The code in my last comment won't work correctly because 'local tasks' (ie, view / edit / etc tabs) are still child items even though they don't get displayed in the menu.
To get around this I counted all the positive IDs in the list, like so:
There are probably better ways to achieve this but, hey, it worked.
--Andy
Developing Drupal websites for Livelink New Media
++Andy
A minor fix
Thanks for this code snippet. It works great for the most part. The only thing i found was that i was getting an error:
warning: Invalid argument supplied for foreach() in .../drupal/includes/common.inc(1355) : eval()'d code on line 5.
Whenever a page was viewed that didn't have any children in the $mitem.
So, i added a simple check and now have this as the code:
I'm not sure if this is the "correct" way to go about this, but it seems to make the error go away.
Thanks again for this snippet. I'd been banging my head on how to get exactly this functionality for a while, and was doing it manually (YUCK!). This has made my life much better.
Child links show on each page
Thanks so much for this kingandy! I've been looking for this answer everywhere. Your little bit of code in a block makes the makes the child level of whatever menu i am in show in the block. Now I can make my site have a true feel of being in different sections.
Most of the code above
Most of the code above pertains to primary links..
has anyone figured out a way to do this for all menus? I would like to display the sublinks of any active menu in a new block, using a php snippet for sublinks in a custom block.
menu block split does exactly this, but I can only get it to work in panels.
http://drupal.org/project/menu_block_split
The obvious answer
The obvious answer is to take out the code that checks for primary menu status - most of these snippets seem to build the menu and then only show it if you're in the primary menu.
Alternatively http://drupal.org/project/local_menu works pretty well, though it's only available for 6.x...
--Andy
Developing Drupal websites for Livelink New Media
++Andy
This worked for me (D6)
In a custom block, with input format set to PHP...
I suppose you could replace 'primary-links' with the machine name of whatever menu you'd like child items for.
I see how we did it in 5.x,
I see how we did it in 5.x, but how can you print menu titles in the above code for 6.x?
Error
I think you meant
Remember it wont be seen on the block admin page, move to a primary link address
"I would rule the world - If only I had the source code"
R.A.Smith -- "ƒrÅzRâ§"
http://www.exterbox.com
menu.inc throws a "for each"
menu.inc throws a "for each" error, there is a fix in this snippet
"I would rule the world - If only I had the source code"
R.A.Smith -- "ƒrÅzRâ§"
http://www.exterbox.com
It would be great to make
It would be great to make themed output of this menu. For example to add id or class for every menu item.
Can somebody provide example for this?
Sasha
Print & Screen